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

About the HTML <strong>en</strong>vironm<strong>en</strong>t<br />

unload ev<strong>en</strong>ts (for body and frameset objects)<br />

Adobe AIR 1.0 and later<br />

In the top-level frameset or body tag of a window (including the main window of the application), do not use the<br />

unload ev<strong>en</strong>t to respond to the window (or application) being closed. Instead, use exiting ev<strong>en</strong>t of the<br />

NativeApplication object (to detect wh<strong>en</strong> an application is closing). Or use the closing ev<strong>en</strong>t of the NativeWindow<br />

object (to detect wh<strong>en</strong> a window is closing). For example, the following JavaScript code displays a message<br />

("Goodbye.") wh<strong>en</strong> the user closes the application:<br />

var app = air.NativeApplication.nativeApplication;<br />

app.addEv<strong>en</strong>tList<strong>en</strong>er(air.Ev<strong>en</strong>t.EXITING, closeHandler);<br />

function closeHandler(ev<strong>en</strong>t)<br />

{<br />

alert("Goodbye.");<br />

}<br />

However, scripts can successfully respond to the unload ev<strong>en</strong>t caused by navigation of a frame, iframe, or top-level<br />

window cont<strong>en</strong>t.<br />

Note: These limitations may be removed in a future version of Adobe AIR.<br />

JavaScript Window object<br />

Adobe AIR 1.0 and later<br />

The Window object remains the global object in the JavaScript execution context. In the application sandbox, AIR<br />

adds new properties to the JavaScript Window object to provide access to the built-in classes of AIR, as well as<br />

important host objects. In addition, some methods and properties behave differ<strong>en</strong>tly dep<strong>en</strong>ding on whether they are<br />

within the application sandbox or not.<br />

Window.runtime property The runtime property allows you to instantiate and use the built-in runtime classes from<br />

within the application sandbox. These classes include the AIR and Flash Player APIs (but not, for example, the Flex<br />

framework). For example, the following statem<strong>en</strong>t creates an AIR file object:<br />

var prefer<strong>en</strong>cesFile = new window.runtime.flash.filesystem.File();<br />

The AIRAliases.js file, provided in the AIR SDK, contains alias definitions that allow you to short<strong>en</strong> such refer<strong>en</strong>ces.<br />

For example, wh<strong>en</strong> AIRAliases.js is imported into a page, a File object can be created with the following statem<strong>en</strong>t:<br />

var prefer<strong>en</strong>cesFile = new air.File();<br />

The window.runtime property is only defined for cont<strong>en</strong>t within the application sandbox and only for the par<strong>en</strong>t<br />

docum<strong>en</strong>t of a page with frames or iframes.<br />

See “Using the AIRAliases.js file” on page 985.<br />

Window.nativeWindow property The nativeWindow property provides a refer<strong>en</strong>ce to the underlying native window<br />

object. With this property, you can script window functions and properties such as scre<strong>en</strong> position, size, and visibility,<br />

and handle window ev<strong>en</strong>ts such as closing, resizing, and moving. For example, the following statem<strong>en</strong>t closes the<br />

window:<br />

window.nativeWindow.close();<br />

Note: The window control features provided by the NativeWindow object overlap the features provided by the JavaScript<br />

Window object. In such cases, you can use whichever method you find most conv<strong>en</strong>i<strong>en</strong>t.<br />

The window.nativeWindow property is only defined for cont<strong>en</strong>t within the application sandbox and only for the<br />

par<strong>en</strong>t docum<strong>en</strong>t of a page with frames or iframes.<br />

Last updated 6/6/2012<br />

968

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

Saved successfully!

Ooh no, something went wrong!