Adding Events - AS3
Events are called whenever the 3DMenu performs the specific action. The 3DMenu-AS3 includes the following events:
Menu3D.INIT
Broadcast upon initializing the 3DMenu
Menu3D.MOUSE_OVER_ITEM
Broadcast upon mouse over items
Menu3D.MOUSE_UP_ITEM
Broadcast upon mouse release on items
Menu3D.MOUSE_DOWN_ITEM
Broadcast upon mouse press on items
Menu3D.MOUSE_OUT_ITEM
Broadcast upon mouse roll out items
Menu3D.ITEM_CHANGE_ADD
Broadcast when an item is added to the 3DMenu
Menu3D.ITEM_CHANGE_REMOVE
Broadcast upon removing an item from the 3DMenu
In order to use an event in ActionScript 3.0 you need to create an event listener method and add the listener method to the component listener list. The following example shows how the initMenu method is called when the 3DMenu is initialized:
//import the event class
import com.flashloaded.as3.Menu3DEvent
//define event method
function initMethod(evt:Menu3DEvent):void {
trace(“init menu.”);
}
//add listener to menu
Menu.addEventListener(Menu3D.INIT,initMethod);
The listener method now listens to the initialize event of the 3DMenu and performs the specified action.
An Event Object contains information that can be used. The following event objects have the same data structure:
Menu3D.MOUSE_OVER_ITEM
Menu3D.MOUSE_UP_ITEM
Menu3D.MOUSE_DOWN_ITEM
Menu3D.MOUSE_OUT_ITEM
Here are the attributes of the event object for the events above:
id :The identifier of the item.
xml :The xml node of the item if the item is initialized through
xml.
item :The object of the item.
target :The target source of the event which is the 3DMenu component.
The following code shows how to access the xml value using an event. You can access the the xml object by using the E4X feature of AS3:
import com.flashloaded.as3.Menu3DEvent;
Function overItem(evt:Menu3DEvent):void {
trace(evt.xml.link); //output the link value from xml.
}
menu.addEventListener(Menu3D.MOUSE_OVER_ITEM,overItem);
Menu3D.ITEM_CHANGE_ADD
Menu3D.ITEM_CHANGE_REMOVE
Here are the attributes of the event object from events above:
Ids : Array that contains id of items that are added or removed. Value type is String.
Items : Array that contains items that are added or removed. Value Type is Sprite.
target : The target source of the event which is the 3DMenu component.
Menu3D.INIT
Here are the attributes of event object from events above.
target :The target source of the event which is the 3DMenu component.