Creative Communications

12 March, 2009

Alpha Properties for TextFields in ActionScript 3

Filed under: Creation,Flash / Interactive,Using Experience — Tags: , , , , — Sean Canton @ 11:51 am

Trying to figure out why those damnable TextFields won’t play nicely with your MovieClips? They just don’t respond to simple things, like setting alpha properties. Fear not! There is a solution! And I won’t forget it this time because I’m writing about it… ;)

Gotta embed those fonts! Here’s the Adobe docs. I won’t venture a technical explanation, only that I assume Flash requires the font vector information to translate the text to a shape, and thus, suitable for raw DisplayObject action.

Step 1: Reference the font. Library > Add Font… Be aware of the name you use here, lets say “Arial” for this example.

Step 2: Make the font available for ActionScript. Library > Font > Linkage. Export for ActionScript in first frame.

Step 3: In your ActionScript:
var tt:TextField = new TextField();
var tf:TextFormat = new TextFormat();
tf.font = "Arial";
tf.color = 0x000000;
tt.defaultTextFormat = tf;
tt.text = "test text";
tt.embedFonts = true;
tt.alpha = .5;

Something else to note. You have to assign a defaultTextFormat before placing text into the TextField, otherwise, it doesn’t work right. Finicky Flash.

Powered by WordPress