How to use dynamic fonts on html using AS3

Challenge:
Most designers find themselves worrying about cross-browser compatibility. Most of the time, they have to work with a limited choice of fonts.

What if you want to do something flashy, like this: http://us.blizzard.com/en-us/company/

Notice the gradient and the drop shadow in the “Company” header. It’s done in flash. And since it’s Blizzard, I assume it runs under a CMS so it’s dynamic. You can change “Company” to “Kompanya” just as easily.


Solution:


1. Design whatever wonderful dynamic text you want in flash.


2. Make sure you embed the characters you want included in the font.


3. Assuming your instance name is “textMC”. Put this in the main timeline:

[as3]

var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
var _text:String = String(params["content"]);
var _orientation:String = String(params["align"]);

var myTextFormat:TextFormat = new TextFormat();
if(_orientation == "center"){
myTextFormat.align = TextFormatAlign.CENTER; //align center
}else if(_orientation == "right"){
myTextFormat.align = TextFormatAlign.RIGHT; //align right
}else{
myTextFormat.align = TextFormatAlign.LEFT; //default alignment is left
}

textMC.text = _text;
textMC.setTextFormat(myTextFormat);

[/as3]


4. In your embed code, specify “content” and “align” in the params. “content” contains your content. If you want to set the alignment set “align” to “center” or “right”. The text aligns to the left by default. Ex:

[as3]
content="This is the content"
[/as3]

Note:
Call setTextFormat() only after you set the text. Flash needs to know the content first, before it can properly format the textfield.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s