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 />

package<br />

{<br />

import flash.text.<strong>en</strong>gine.*;<br />

import flash.display.Sprite;<br />

}<br />

public class ReplaceTextExample ext<strong>en</strong>ds Sprite<br />

{<br />

public function ReplaceTextExample()<br />

{<br />

}<br />

}<br />

var str:String = "Lorem ipsum dolor sit amet";<br />

var fontDescription:FontDescription = new FontDescription("Arial");<br />

var format:Elem<strong>en</strong>tFormat = new Elem<strong>en</strong>tFormat(fontDescription);<br />

format.fontSize = 14;<br />

var textElem<strong>en</strong>t:TextElem<strong>en</strong>t = new TextElem<strong>en</strong>t(str, format);<br />

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

textBlock.cont<strong>en</strong>t = textElem<strong>en</strong>t;<br />

createLine(textBlock, 10);<br />

textElem<strong>en</strong>t.replaceText(0, 0, "A text fragm<strong>en</strong>t: ");<br />

createLine(textBlock, 30);<br />

textElem<strong>en</strong>t.replaceText(43, 43, "...");<br />

createLine(textBlock, 50);<br />

textElem<strong>en</strong>t.replaceText(23, 28, "(ipsum)");<br />

createLine(textBlock, 70);<br />

function createLine(textBlock:TextBlock, y:Number):void {<br />

var textLine:TextLine = textBlock.createTextLine(null, 300);<br />

textLine.x = 10;<br />

textLine.y = y;<br />

addChild(textLine);<br />

}<br />

The replaceText() method replaces the text specified by the beginIndex and <strong>en</strong>dIndex parameters with the text<br />

specified by the newText parameter. If the values of the beginIndex and <strong>en</strong>dIndex parameters are the same,<br />

replaceText() inserts the specified text at that location. Otherwise it replaces the characters specified by beginIndex<br />

and <strong>en</strong>dIndex with the new text.<br />

Handling Ev<strong>en</strong>ts in FTE<br />

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

You can add ev<strong>en</strong>t list<strong>en</strong>ers to a TextLine instance just as you can to other display objects. For example, you can detect<br />

wh<strong>en</strong> a user rolls the mouse over a text line or a user clicks the line. The following example detects both of these ev<strong>en</strong>ts.<br />

Wh<strong>en</strong> you roll the mouse over the line, the cursor changes to a button cursor and wh<strong>en</strong> you click the line, it changes<br />

color.<br />

Last updated 6/6/2012<br />

401

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

Saved successfully!

Ooh no, something went wrong!