Friday, November 19, 2010

How do you change font and color of static text using coding in CS3 flash Actionscript 3?

Can you give me an example on how to write the coding on formatting a static text in flash so I can get started on it. ThanksHow do you change font and color of static text using coding in CS3 flash Actionscript 3?
import flash.text.TextField;

import flash.text.TextFieldAutoSize;

import flash.text.TextFormat;



var myText:TextField = new TextField();





var myFormat:TextFormat = new TextFormat();

myFormat.font = ';Verdana';;

myFormat.color = 0xFF0000;

myFormat.size = 10;

myFormat.bold=true;

myFormat.leftMargin=5;

myFormat.underline = true;



myText.defaultTextFormat = myFormat;







myText.text=(';formatted text';);



addChild(myText);



when you type in the myFormat. you will get a list of attributes you can play with i've only included themore common ones.



All thats happening is by default flash uses default format (color black etc), so you create a new instance of the new Format class and give it a name. this new class you then populate with attributes such as bold, leftmargin, colour etc and this is used to define the new default for your text.

No comments:

Post a Comment