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

Justifying text<br />

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

Justifying text makes all lines in a paragraph the same l<strong>en</strong>gth by adjusting the spacing betwe<strong>en</strong> words and sometimes<br />

betwe<strong>en</strong> letters. The effect is to align the text on both sides, while the spacing betwe<strong>en</strong> words and letters varies.<br />

Columns of text in newspapers and magazines are frequ<strong>en</strong>tly justified.<br />

The lineJustfication property in the SpaceJustifier class allows you to control the justification of lines in a block<br />

of text. The LineJustification class defines constants that you can use to specify a justification option: ALL_BUT_LAST<br />

justifies all but the last line of text; ALL_INCLUDING_LAST justifies all text, including the last line; UNJUSTIFIED, which<br />

is the default, leaves the text unjustified.<br />

To justify text, set the lineJustification property to an instance of the SpaceJustifier class and assign that instance<br />

to the textJustifier property of a TextBlock instance. The following example creates a paragraph in which all but<br />

the last line of text is justified.<br />

package<br />

{<br />

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

import flash.display.Sprite;<br />

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

{<br />

public function JustifyExample()<br />

{<br />

var str:String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " +<br />

"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut " +<br />

"<strong>en</strong>im ad minim v<strong>en</strong>iam, quis nostrud exercitation ullamco laboris nisi ut " +<br />

"aliquip ex ea commodo consequat.";<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 spaceJustifier:SpaceJustifier=new<br />

SpaceJustifier("<strong>en</strong>",LineJustification.ALL_BUT_LAST);<br />

}<br />

}<br />

}<br />

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

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

textBlock.textJustifier=spaceJustifier;<br />

createLines(textBlock);<br />

private function createLines(textBlock:TextBlock):void {<br />

var yPos=20;<br />

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

}<br />

while (textLine) {<br />

addChild(textLine);<br />

textLine.x=15;<br />

yPos+=textLine.textHeight+2;<br />

textLine.y=yPos;<br />

textLine=textBlock.createTextLine(textLine,150);<br />

}<br />

Last updated 6/6/2012<br />

412

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

Saved successfully!

Ooh no, something went wrong!