13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Using the TextField class<br />

var format:TextFormat = new TextFormat();<br />

format.color = 0x336699;<br />

format.size = 48;<br />

format.font = "myFont";<br />

var myText:TextField = new TextField();<br />

myText.embedFonts = true;<br />

myText.autoSize = TextFieldAutoSize.LEFT;<br />

myText.antiAliasType = AntiAliasType.ADVANCED;<br />

myText.defaultTextFormat = format;<br />

myText.selectable = false;<br />

myText.mouseEnabled = true;<br />

myText.text = "Hello World";<br />

addChild(myText);<br />

myText.addEv<strong>en</strong>tList<strong>en</strong>er(MouseEv<strong>en</strong>t.CLICK, clickHandler);<br />

function clickHandler(ev<strong>en</strong>t:Ev<strong>en</strong>t):void<br />

{<br />

var myAntiAliasSettings = new CSMSettings(48, 0.8, -0.8);<br />

var myAliasTable:Array = new Array(myAntiAliasSettings);<br />

TextR<strong>en</strong>derer.setAdvancedAntiAliasingTable("myFont", FontStyle.ITALIC,<br />

TextColorType.DARK_COLOR, myAliasTable);<br />

}<br />

Working with static text<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Static text is created only within Flash Professional. You cannot programmatically instantiate static text using<br />

ActionScript. Static text is useful if the text is short and is not int<strong>en</strong>ded to change (as dynamic text can). Think of static<br />

text as similar to a graphic elem<strong>en</strong>t like a circle or square drawn on the Stage in Flash Professional. While static text is<br />

more limited than dynamic text, ActionScript 3.0 does allow you to read the property values of static text using the<br />

StaticText class. You can also use the TextSnapshot class to read values out of the static text.<br />

Accessing static text fields with the StaticText class<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Typically, you use the flash.text.StaticText class in the Actions panel of Flash Professional to interact with a static text<br />

instance placed on the Stage. You may also work in ActionScript files that interact with a SWF file containing static<br />

text. In either case, you can’t instantiate a static text instance programmatically. Static text is created in Flash<br />

Professional.<br />

To create a refer<strong>en</strong>ce to an existing static text field, iterate over the items in the display list and assign a variable. For<br />

example:<br />

Last updated 6/6/2012<br />

386

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!