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 Flash Text Engine<br />

package<br />

{<br />

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

import flash.display.Sprite;<br />

}<br />

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

{<br />

public function HelloWorldExample()<br />

{<br />

var str = "Hello World! This is Flash Text Engine!";<br />

var format:Elem<strong>en</strong>tFormat = new Elem<strong>en</strong>tFormat();<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 />

}<br />

}<br />

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

addChild(textLine1);<br />

textLine1.x = 30;<br />

textLine1.y = 30;<br />

The parameters for createTextLine() specify the line from which to begin the new line and the width of the line in<br />

pixels. The line from which to begin the new line is usually the previous line but, in the case of the first line, it is null.<br />

Adding GraphicElem<strong>en</strong>t and GroupElem<strong>en</strong>t objects<br />

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

You can assign a GraphicElem<strong>en</strong>t object to a TextBlock object to display an image or a graphic elem<strong>en</strong>t. Simply create<br />

an instance of the GraphicElem<strong>en</strong>t class from a graphic or an image and assign the instance to the<br />

TextBlock.cont<strong>en</strong>t property. Create the text line by calling TextBlock.createTextline() as you normally would.<br />

The following example creates two text lines, one with a GraphicElem<strong>en</strong>t object and one with a TextElem<strong>en</strong>t object.<br />

package<br />

{<br />

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

import flash.display.Sprite;<br />

import flash.display.Shape;<br />

import flash.display.Graphics;<br />

public class GraphicElem<strong>en</strong>tExample ext<strong>en</strong>ds Sprite<br />

{<br />

public function GraphicElem<strong>en</strong>tExample()<br />

{<br />

var str:String = "Beware of Dog!";<br />

var triangle:Shape = new Shape();<br />

triangle.graphics.beginFill(0xFF0000, 1);<br />

triangle.graphics.lineStyle(3);<br />

triangle.graphics.moveTo(30, 0);<br />

triangle.graphics.lineTo(60, 50);<br />

triangle.graphics.lineTo(0, 50);<br />

triangle.graphics.lineTo(30, 0);<br />

triangle.graphics.<strong>en</strong>dFill();<br />

Last updated 6/6/2012<br />

398

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

Saved successfully!

Ooh no, something went wrong!