Using an embedded font with the TextArea control in Flash with ActionScript 3.0

by Peter deHaan on November 26, 2008

in TextArea

The following example shows how you can use an embedded font with the Flash ActionScript 3.0 TextArea control.

Full code after the jump.

Note: The following example requires a TextArea control in your Flash document’s library, as well as an embedded font with the linkage class set to “ChaparralProEmbedded”.

// ActionScript 3.0
import fl.controls.TextArea;
 
var chaparralProEmbeddedFont:Font = new ChaparralProEmbedded();
 
var textFormat:TextFormat = new TextFormat();
textFormat.font = chaparralProEmbeddedFont.fontName;
textFormat.size = 32;
 
var textArea:TextArea = new TextArea();
textArea.setStyle("textFormat", textFormat);
textArea.setStyle("embedFonts", true);
textArea.text = "The quick brown dog jumps over the lazy fox.";
textArea.move(10, 10);
textArea.setSize(300, 200);
addChild(textArea);

{ 3 comments… read them below or add one }

1 Bhavya Technologies 02.08.09 at 9:56 am

Anybody can help me in how to Reading Text files using action script.

2 chichilatte 07.22.09 at 5:48 am

@Bhavya
In Flash authortime, make sure you have the TextArea component in your library, stick this code on your main timeline and publish. Course you’ll need a text file to load too.

import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import fl.controls.TextArea;
 
var fileLoader:URLLoader;
var yourTextArea:TextArea = new TextArea();
addChild(yourTextArea);
 
loadFile("your_text_file.txt");
 
 
 
 
function loadFile(url:String) {
	fileLoader = new URLLoader();
	fileLoader.addEventListener(IOErrorEvent.IO_ERROR , onFileLoadError);
	fileLoader.addEventListener(Event.COMPLETE, onFileLoadComplete);
	fileLoader.load(new URLRequest(url));
}
 
function onFileLoadComplete(event:Event):void {
	fileLoader.removeEventListener(Event.COMPLETE, onFileLoadComplete);
	fileLoader.removeEventListener(IOErrorEvent.IO_ERROR , onFileLoadError);
	yourTextArea.htmlText = event.target.data as String;
}
 
function onFileLoadError(event:IOErrorEvent):void {
	trace("Could not load text ");
}
3 daniel 10.05.09 at 7:10 am

thank you so much.
works like a charm….:-)

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: