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

Display programming<br />

Manual ori<strong>en</strong>tation<br />

AIR 2.6 and later<br />

You can control the stage ori<strong>en</strong>tation using the Stage setOri<strong>en</strong>tation() or setAspectRatio() methods.<br />

Setting the stage ori<strong>en</strong>tation<br />

You can set the stage ori<strong>en</strong>tation at runtime using the setOri<strong>en</strong>tation() method of the Stage object. Use the string<br />

constants defined by the StageOri<strong>en</strong>tation class to specify the desired ori<strong>en</strong>tation:<br />

this.stage.setOri<strong>en</strong>tation( StageOri<strong>en</strong>tation.ROTATED_RIGHT );<br />

Not every device and operating system supports every possible ori<strong>en</strong>tation. For example, Android 2.2 does not support<br />

programmatically choosing the rotated-left ori<strong>en</strong>tation on portrait-standard devices and does not support the upsidedown<br />

ori<strong>en</strong>tation at all. The supportedOri<strong>en</strong>tations property of the stage provides a list of the ori<strong>en</strong>tations that can<br />

be passed to the setOri<strong>en</strong>tation() method:<br />

var ori<strong>en</strong>tations:Vector. = this.stage.supportedOri<strong>en</strong>tations;<br />

for each( var ori<strong>en</strong>tation:String in ori<strong>en</strong>tations )<br />

{<br />

trace( ori<strong>en</strong>tation );<br />

}<br />

Setting the stage aspect ratio<br />

If you are primarily concerned about the aspect ratio of the stage, you can set the aspect ratio to portrait or landscape.<br />

You can set the aspect ratio in either the AIR application descriptor or, at run time, using the Stage setAspectRatio()<br />

method:<br />

this.stage.setAspectRatio( StageAspectRatio.LANDSCAPE );<br />

The runtime chooses one of the two possible ori<strong>en</strong>tations for the specified aspect ratio. This may not match the curr<strong>en</strong>t<br />

device ori<strong>en</strong>tation. For example, the default ori<strong>en</strong>tation is chos<strong>en</strong> in prefer<strong>en</strong>ce to the upside-down ori<strong>en</strong>tation (AIR<br />

3.2 and earlier) and the ori<strong>en</strong>tation appropriate for the slide-out keyboard is chos<strong>en</strong> in prefer<strong>en</strong>ce to the opposite<br />

ori<strong>en</strong>tation.<br />

(AIR 3.3 and higher) Starting with AIR 3.3 (SWF version 16), you can also use the StageAspectRatio.ANY constant.<br />

If Stage.autoOri<strong>en</strong>ts is set to true and you call setAspectRatio(StageAspectRatio.ANY), your application has<br />

the capability to re-ori<strong>en</strong>t to all ori<strong>en</strong>tations (landscape-left, landscape-right, portait, and portrait-upside-down). Also<br />

new in AIR 3.3, the aspect ratio is persist<strong>en</strong>t, and further rotation of the device is constrained to the specified<br />

ori<strong>en</strong>tation.<br />

Example: Setting the stage ori<strong>en</strong>tation to match the device ori<strong>en</strong>tation<br />

The following example illustrates a function that updates the stage ori<strong>en</strong>tation to match the curr<strong>en</strong>t device ori<strong>en</strong>tation.<br />

The stage deviceOri<strong>en</strong>tation property indicates the physical ori<strong>en</strong>tation of the device, ev<strong>en</strong> wh<strong>en</strong> auto-ori<strong>en</strong>tation<br />

is turned off.<br />

Last updated 6/6/2012<br />

197

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

Saved successfully!

Ooh no, something went wrong!