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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Using the Flash Text Engine<br />

The mouseOverHandler() and mouseOutHandler() functions set the cursor to a button cursor wh<strong>en</strong> it's over the<br />

word "here" and back to an arrow wh<strong>en</strong> it's not.<br />

Formatting text<br />

Flash Player 10 and later, Adobe AIR 1.5 and later<br />

A TextBlock object is a factory for creating lines of text. The cont<strong>en</strong>t of a TextBlock is assigned via the TextElem<strong>en</strong>t<br />

object. An Elem<strong>en</strong>tFormat object handles the formatting for the text. The Elem<strong>en</strong>tFormat class defines such<br />

properties as baseline alignm<strong>en</strong>t, kerning, tracking, text rotation, and font size, color, and case. It also includes a<br />

FontDescription, which is covered in detail in “Working with fonts” on page 409.<br />

Using the Elem<strong>en</strong>tFormat object<br />

Flash Player 10 and later, Adobe AIR 1.5 and later<br />

The constructor for the Elem<strong>en</strong>tFormat object takes any of a long list of optional parameters, including a<br />

FontDescription. You can also set these properties outside the constructor. The following example shows the<br />

relationship of the various objects in defining and displaying a simple text line:<br />

package<br />

{<br />

import flash.display.Sprite;<br />

import flash.text.*;<br />

}<br />

public class Elem<strong>en</strong>tFormatExample ext<strong>en</strong>ds Sprite<br />

{<br />

private var tb:TextBlock = new TextBlock();<br />

private var te:TextElem<strong>en</strong>t;<br />

private var ef:Elem<strong>en</strong>tFormat;<br />

private var fd:FontDescription = new FontDescription();<br />

private var str:String;<br />

private var tl:TextLine;<br />

}<br />

public function Elem<strong>en</strong>tFormatExample()<br />

{<br />

fd.fontName = "Garamond";<br />

ef = new Elem<strong>en</strong>tFormat(fd);<br />

ef.fontSize = 30;<br />

ef.color = 0xFF0000;<br />

str = "This is flash text";<br />

te = new TextElem<strong>en</strong>t(str, ef);<br />

tb.cont<strong>en</strong>t = te;<br />

tl = tb.createTextLine(null,600);<br />

addChild(tl);<br />

}<br />

Last updated 6/6/2012<br />

405

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

Saved successfully!

Ooh no, something went wrong!