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

Working with AIR native windows<br />

Wh<strong>en</strong> you create a window with the Flex mx:Window class, specify the initialization properties on the window object<br />

itself, either in the MXML declaration for the window, or in the code that creates the window. The underlying<br />

NativeWindow object is not created until you call the op<strong>en</strong>() method. Once a window is op<strong>en</strong>ed, these initialization<br />

properties cannot be changed.<br />

Creating the initial application window<br />

Adobe AIR 1.0 and later<br />

AIR creates the initial application window based on the properties specified in the application descriptor and loads the<br />

file refer<strong>en</strong>ced in the cont<strong>en</strong>t elem<strong>en</strong>t. The cont<strong>en</strong>t elem<strong>en</strong>t must refer<strong>en</strong>ce a SWF file or an HTML file.<br />

The initial window can be the main window of your application or it can merely serve to launch one or more other<br />

windows. You do not have to make it visible at all.<br />

Creating the initial window with ActionScript<br />

Adobe AIR 1.0 and later<br />

Wh<strong>en</strong> you create an AIR application using ActionScript, the main class of your application must ext<strong>en</strong>d the Sprite class<br />

(or a subclass of Sprite). This class serves as the main <strong>en</strong>try point for the application.<br />

Wh<strong>en</strong> your application launches, AIR creates a window, creates an instance of the main class, and adds the instance to<br />

the window stage. To access the window, you can list<strong>en</strong> for the addedToStage ev<strong>en</strong>t and th<strong>en</strong> use the nativeWindow<br />

property of the Stage object to get a refer<strong>en</strong>ce to the NativeWindow object.<br />

The following example illustrates the basic skeleton for the main class of an AIR application built with ActionScript:<br />

}<br />

package {<br />

import flash.display.NativeWindow;<br />

import flash.display.Sprite;<br />

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

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

{<br />

private var mainWindow:NativeWindow;<br />

public function MainClass(){<br />

this.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.ADDED_TO_STAGE, initialize);<br />

}<br />

}<br />

private function initialize(ev<strong>en</strong>t:Ev<strong>en</strong>t):void{<br />

mainWindow = this.stage.nativeWindow;<br />

//perform initialization...<br />

mainWindow.activate(); //show the window<br />

}<br />

Note: Technically, you CAN access the nativeWindow property in the constructor function of the main class. However,<br />

this is a special case applying only to the initial application window.<br />

Wh<strong>en</strong> creating an application in Flash Professional, the main docum<strong>en</strong>t class is created automatically if you do not<br />

create your own in a separate ActionScript file. You can access the NativeWindow object for the initial window using<br />

the stage nativeWindow property. For example, the following code activates the main window in the maximized state<br />

(from the timeline):<br />

Last updated 6/6/2012<br />

898

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

Saved successfully!

Ooh no, something went wrong!