Description
Event; broadcast to all registered listeners when the pointer rolls off a menu item.
Version 2 components use a dispatcher-listener event model. When a Menu component
broadcasts a
event, the event is handled by a function (also called a handler) that is
rollOut
attached to a listener object (
) that you create. You call the
listenerObject
method and pass it the name of the handler as a parameter.
addEventListener()
When the event is triggered, it automatically passes an event object (
) to the
eventObject
handler. Each event object has properties that contain information about the event. You can
use these properties to write code that handles the event. The
event's event
Menu.rollOut
object has one additional property:
, which is a reference to the menu item (XML
menuItem
node) that the pointer rolled off.
For more information, see
"EventDispatcher class" on page
499.
Example
The following example creates a menu with two items and a listener for a
event.
rollOut
When the
event is broadcast, a
() function in the event handler,
rollOut
trace
, displays the name of the menu item for which the event occurred.
menuListener
You first drag a Menu component to the library and then add the following code to Frame 1:
/**
Requires:
- Menu component in library
*/
import mx.controls.Menu;
// Create an XML object to act as a factory.
var my_xml:XML = new XML();
// The item created next does not appear in the menu.
// The createMenu() method call (below) expects to
// receive a root element whose children will become
// the items. This is just a simple way to create that
// root element and give it a convenient name.
var menuDP_obj:Object = my_xml.addMenuItem("XXXXX");
// Add the menu items.
menuDP_obj.addMenuItem({label:"1st Item"});
menuDP_obj.addMenuItem({label:"2nd Item"});
// Create the Menu object.
var my_menu:Menu = Menu.createMenu(this, menuDP_obj);
// Show and position the menus.
926
Menu component (Flash Professional only)
Need help?
Do you have a question about the FLASH 8-COMPONENTS LANGUAGE and is the answer not in the manual?