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

How to Use ActionScript Examples<br />

Stage size<br />

The stage size you use wh<strong>en</strong> running an example on a mobile device is much smaller than wh<strong>en</strong> you use a non-mobile<br />

device. Many examples do not require a particular Stage size. Wh<strong>en</strong> creating the SWF file, specify a Stage size<br />

appropriate to your device. For example, specify 176 x 208 pixels.<br />

The purpose of the practical examples in the ActionScript 3.0 Developm<strong>en</strong>t <strong>Guide</strong> is to illustrate differ<strong>en</strong>t ActionScript<br />

3.0 concepts and classes. Their user interfaces are designed to look good and work well on a desktop or laptop<br />

computer. Although the examples work on mobile devices, the Stage size and user interface design is not suitable to<br />

the small scre<strong>en</strong>. Adobe recomm<strong>en</strong>ds that you run the practical examples on a computer to learn the ActionScript, and<br />

th<strong>en</strong> use pertin<strong>en</strong>t code snippets in your mobile applications.<br />

Text fields instead of trace statem<strong>en</strong>ts<br />

Wh<strong>en</strong> running an example on a mobile device, you cannot see the output from the example’s trace statem<strong>en</strong>ts. To see<br />

the output, create an instance of the TextField class. Th<strong>en</strong>, app<strong>en</strong>d the text from the trace statem<strong>en</strong>ts to the text<br />

property of the text field.<br />

You can use the following function to set up a text field to use for tracing:<br />

function createTracingTextField(x:Number, y:Number,<br />

width:Number, height:Number):TextField {<br />

}<br />

var tracingTF:TextField = new TextField();<br />

tracingTF.x = x;<br />

tracingTF.y = y;<br />

tracingTF.width = width;<br />

tracingTF.height = height;<br />

// A border lets you more easily see the area the text field covers.<br />

tracingTF.border = true;<br />

// Left justifying means that the right side of the text field is automatically<br />

// resized if a line of text is wider than the width of the text field.<br />

// The bottom is also automatically resized if the number of lines of text<br />

// exceed the l<strong>en</strong>gth of the text field.<br />

tracingTF.autoSize = TextFieldAutoSize.LEFT;<br />

// Use a text size that works well on the device.<br />

var myFormat:TextFormat = new TextFormat();<br />

myFormat.size = 18;<br />

tracingTF.defaultTextFormat = myFormat;<br />

addChild(tracingTF);<br />

return tracingTF;<br />

For example, add this function to the docum<strong>en</strong>t class as a private function. Th<strong>en</strong>, in other methods of the docum<strong>en</strong>t<br />

class, trace data with code like the following:<br />

var traceField:TextField = createTracingTextField(10, 10, 150, 150);<br />

// Use the newline character "\n" to force the text to the next line.<br />

traceField.app<strong>en</strong>dText("data to trace\n");<br />

traceField.app<strong>en</strong>dText("more data to trace\n");<br />

// Use the following line to clear the text field.<br />

traceField.app<strong>en</strong>dText("");<br />

Last updated 6/6/2012<br />

1090

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

Saved successfully!

Ooh no, something went wrong!