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

Working with m<strong>en</strong>us<br />

Attaching an object to a m<strong>en</strong>u item<br />

Adobe AIR 1.0 and later<br />

The data property of the NativeM<strong>en</strong>uItem class allows you to refer<strong>en</strong>ce an arbitrary object in each item. For example,<br />

in an “Op<strong>en</strong> Rec<strong>en</strong>t” m<strong>en</strong>u, you could assign the File object for each docum<strong>en</strong>t to each m<strong>en</strong>u item.<br />

var file:File = File.applicationStorageDirectory.resolvePath("GreatGatsby.pdf")<br />

var m<strong>en</strong>uItem:NativeM<strong>en</strong>uItem = docM<strong>en</strong>u.addItem(new NativeM<strong>en</strong>uItem(file.name));<br />

m<strong>en</strong>uItem.data = file;<br />

Creating native m<strong>en</strong>us (AIR)<br />

Adobe AIR 1.0 and later<br />

This topic describes how to create the various types of native m<strong>en</strong>u supported by AIR.<br />

Creating a root m<strong>en</strong>u object<br />

Adobe AIR 1.0 and later<br />

To create a NativeM<strong>en</strong>u object to serve as the root of the m<strong>en</strong>u, use the NativeM<strong>en</strong>u constructor:<br />

var root:NativeM<strong>en</strong>u = new NativeM<strong>en</strong>u();<br />

For application and window m<strong>en</strong>us, the root m<strong>en</strong>u repres<strong>en</strong>ts the m<strong>en</strong>u bar and should only contain items that op<strong>en</strong><br />

subm<strong>en</strong>us. Context m<strong>en</strong>u and pop-up m<strong>en</strong>us do not have a m<strong>en</strong>u bar, so the root m<strong>en</strong>u can contain commands and<br />

separator lines as well as subm<strong>en</strong>us.<br />

After the m<strong>en</strong>u is created, you can add m<strong>en</strong>u items. Items appear in the m<strong>en</strong>u in the order in which they are added,<br />

unless you add the items at a specific index using the addItemAt() method of a m<strong>en</strong>u object.<br />

Assign the m<strong>en</strong>u as an application, window, icon, or context m<strong>en</strong>u, or display it as a pop-up m<strong>en</strong>u as shown in the<br />

following sections:<br />

Setting the application m<strong>en</strong>u or window m<strong>en</strong>u<br />

It’s important that your code accommodate both application m<strong>en</strong>us (supported on Mac OS) and window m<strong>en</strong>us<br />

(supported on other operating systems)<br />

var root:NativeM<strong>en</strong>u = new NativeM<strong>en</strong>u();<br />

if (NativeApplication.supportsM<strong>en</strong>u)<br />

{<br />

NativeApplication.nativeApplication.m<strong>en</strong>u = root;<br />

}<br />

else if (NativeWindow.supportsM<strong>en</strong>u)<br />

{<br />

nativeWindow.m<strong>en</strong>u = root;<br />

}<br />

Note: Mac OS defines a m<strong>en</strong>u containing standard items for every application. Assigning a new NativeM<strong>en</strong>u object to<br />

the m<strong>en</strong>u property of the NativeApplication object replaces the standard m<strong>en</strong>u. You can also use the standard m<strong>en</strong>u<br />

instead of replacing it.<br />

Last updated 6/6/2012<br />

638

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

Saved successfully!

Ooh no, something went wrong!