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

}<br />

}<br />

}<br />

Mirroring ev<strong>en</strong>ts<br />

switch(newFormat.color)<br />

{<br />

case 0x000000:<br />

newFormat.color = 0xFF0000;<br />

break;<br />

case 0xFF0000:<br />

newFormat.color = 0x00FF00;<br />

break;<br />

case 0x00FF00:<br />

newFormat.color = 0x0000FF;<br />

break;<br />

case 0x0000FF:<br />

newFormat.color = 0x000000;<br />

break;<br />

}<br />

textBlock.cont<strong>en</strong>t.elem<strong>en</strong>tFormat = newFormat;<br />

createLine(textBlock);<br />

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

You can also mirror ev<strong>en</strong>ts on a text block, or on a portion of a text block, to an ev<strong>en</strong>t dispatcher. First, create an<br />

Ev<strong>en</strong>tDispatcher instance and th<strong>en</strong> assign it to the ev<strong>en</strong>tMirror property of a TextElem<strong>en</strong>t instance. If the text block<br />

consists of a single text elem<strong>en</strong>t, the text <strong>en</strong>gine mirrors ev<strong>en</strong>ts for the <strong>en</strong>tire text block. If the text block consists of<br />

multiple text elem<strong>en</strong>ts, the text <strong>en</strong>gine mirrors ev<strong>en</strong>ts only for the TextElem<strong>en</strong>t instances that have the ev<strong>en</strong>tMirror<br />

property set. The text in the following example consists of three elem<strong>en</strong>ts: the word "Click", the word "here", and the<br />

string "to see me in italic". The example assigns an ev<strong>en</strong>t dispatcher to the second text elem<strong>en</strong>t, the word "here", and<br />

adds an ev<strong>en</strong>t list<strong>en</strong>er, the clickHandler() method. The clickHandler() method changes the text to italic. It also<br />

replaces the cont<strong>en</strong>t of the third text elem<strong>en</strong>t to read, "Click here to see me in normal font!".<br />

package<br />

{<br />

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

import flash.ui.Mouse;<br />

import flash.display.Sprite;<br />

import flash.ev<strong>en</strong>ts.MouseEv<strong>en</strong>t;<br />

import flash.ev<strong>en</strong>ts.Ev<strong>en</strong>tDispatcher;<br />

public class Ev<strong>en</strong>tMirrorExample ext<strong>en</strong>ds Sprite<br />

{<br />

var fontDescription:FontDescription = new FontDescription("Helvetica", "bold");<br />

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

var textElem<strong>en</strong>t1 = new TextElem<strong>en</strong>t("Click ", format);<br />

var textElem<strong>en</strong>t2 = new TextElem<strong>en</strong>t("here ", format);<br />

var textElem<strong>en</strong>t3 = new TextElem<strong>en</strong>t("to see me in italic! ", format);<br />

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

public function Ev<strong>en</strong>tMirrorExample()<br />

{<br />

var myEv<strong>en</strong>t:Ev<strong>en</strong>tDispatcher = new Ev<strong>en</strong>tDispatcher();<br />

Last updated 6/6/2012<br />

403

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

Saved successfully!

Ooh no, something went wrong!