onMenuClick This page was last modified over 30 day(s) ago and has 1 comment(s)


Back to Menu.Main Class Summary

Availability
Windows, Mac OSX, Linux

Usage
mdm.Menu.Main.onMenuClick:Function

Parameters
None

Returns
Nothing

Description
Event "onMenuClick" is dispatched when the user clicks on a menu item. The handler for event can be assigned to this method or could be added via addEventListener method of mdm.Menu.Main

Notes
There are two ways to listen for events in 4.0:
#1
using "onEventNameFunction" - callback based handlers introduced in {mdm} 2.0
#2
using IEventListener model based on Events introduced in 4.0.

No matter what implementation you would use either callback and listener handler would have to use single-argument defintion as in below sample:
// callback based handlers
mdm.Appllication.onAppChangeFocus = function(event:Event):void
{
// proceed with event
};

// handlers based on IEventListener model
function onAppChangeFocusHandler(event:Event):void
{
// proceed with event
};

The event for mdm.Menu.Main will have "name" property available at path:
event.data.name
"name" property will correspond to name of menu item clicked

This menu type is not supported in transparent Forms.

Example Code
// to efficiently handle menu items and
// to avoid typos use variable defined labels
var fileHeaderLabel:String = "File";
var openFileMenuItem:String = "Open";
var closeFileMenUItem:String = "Close File";
var exitMenuItem:String = "Quit MyApplication";

// next assign handler to handle click on menu
mdm.Menu.Main.onMenuClick = onMenuClickHandler;
// create menu items
mdm.Menu.Main.insertHeader(fileHeaderLabel);
mdm.Menu.Main.insertItem(fileHeaderLabel, openFileMenuItem);
mdm.Menu.Main.insertItem(fileHeaderLabel, closeFileMenUItem);
mdm.Menu.Main.insertDivider(fileHeaderLabel);
mdm.Menu.Main.insertItem(fileHeaderLabel, exitMenuItem);


// function will be called to handle menu events
function onMenuClickHandler(event:mdm.Event):void
{
// event.type = "onMenuClick"
// event.data.name
if(event.data.name == openFileMenuItem)
{
openFileAction();
} else if(event.data.name == closeFileMenUItem)
{
closeFileAction();
} else if(event.data.name == exitMenuItem)
{
exitAction();
};
}

// the other way to assign handler to onMenuClick
mdm.Menu.Main.addEventListener("onMenuClick", onMenuClickHandler);

// the other way to handle events efficiently
function onMenuClickHandler(event:mdm.Event):void
{
switch(event.data.name)
{
case openFileMenuItem:
openFileAction();
break;
case closeFileMenUItem:
closeFileAction();
break;
case exitMenuItem:
exitAction();
break;
};
}

mdm.Menu.Main Class Example Downloads
No Example Downloads Available


User Comment by Samer on 28th December 2012 - 21:35
I wrote Previous example but in flash give me this message:
Scene 1, Layer 'Layer 2', Frame 1, Line 64 1180: Call to a possibly undefined method openFileAction.
Scene 1, Layer 'Layer 2', Frame 1, Line 67 1180: Call to a possibly undefined method closeFileAction.
Scene 1, Layer 'Layer 2', Frame 1, Line 70 1180: Call to a possibly undefined method exitAction.
What Is problem

Registered Users must be logged in to 'MyAccount' to add a Comment - Log In Here
  After Logging In, Click Here to Refresh This Page