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 m<strong>en</strong>us<br />

<br />

<br />

<br />

<br />

function showContextM<strong>en</strong>u(ev<strong>en</strong>t){<br />

ev<strong>en</strong>t.prev<strong>en</strong>tDefault();<br />

contextM<strong>en</strong>u.display(window.nativeWindow.stage, ev<strong>en</strong>t.cli<strong>en</strong>tX, ev<strong>en</strong>t.cli<strong>en</strong>tY);<br />

}<br />

function createContextM<strong>en</strong>u(){<br />

var m<strong>en</strong>u = new air.NativeM<strong>en</strong>u();<br />

var command = m<strong>en</strong>u.addItem(new air.NativeM<strong>en</strong>uItem("Custom command"));<br />

command.addEv<strong>en</strong>tList<strong>en</strong>er(air.Ev<strong>en</strong>t.SELECT, onCommand);<br />

return m<strong>en</strong>u;<br />

}<br />

function onCommand(){<br />

air.trace("Context command invoked.");<br />

}<br />

var contextM<strong>en</strong>u = createContextM<strong>en</strong>u();<br />

<br />

<br />

<br />

Custom context<br />

m<strong>en</strong>u.<br />

<br />

<br />

Displaying pop-up native m<strong>en</strong>us (AIR)<br />

Adobe AIR 1.0 and later<br />

You can display any NativeM<strong>en</strong>u object at an arbitrary time and location above a window, by calling the m<strong>en</strong>u<br />

display() method. The method requires a refer<strong>en</strong>ce to the stage; thus, only cont<strong>en</strong>t in the application sandbox can<br />

display a m<strong>en</strong>u as a pop-up.<br />

The following method displays the m<strong>en</strong>u defined by a NativeM<strong>en</strong>u object named popupM<strong>en</strong>u in response to a mouse<br />

click:<br />

private function onMouseClick(ev<strong>en</strong>t:MouseEv<strong>en</strong>t):void {<br />

popupM<strong>en</strong>u.display(ev<strong>en</strong>t.target.stage, ev<strong>en</strong>t.stageX, ev<strong>en</strong>t.stageY);<br />

}<br />

Note: The m<strong>en</strong>u does not need to be displayed in direct response to an ev<strong>en</strong>t. Any method can call the display()<br />

function.<br />

Last updated 6/6/2012<br />

641

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

Saved successfully!

Ooh no, something went wrong!