Adding Events - AS2
Events are called whenever the 3DMenu performs a specific action. The 3DMenu includes the following events:
onInit
Broadcast upon initialization of the 3DMenu
onXMLLoadFailed
Broadcast when XML loading has failed
onRemoveItem
Broadcast when an item has been removed
onRemoveAllItem
Broadcast when all items have been removed
onAddItem
Broadcast upon adding a new item
In order to use the event handlers, you need to create an event listener which must be added the listener to component listener list. The following example shows how to execute an event upon initialization of the 3DMenu:
var lis={};
lis.onInit=function(evt:Object){
trace(“init”);
}
//add listener to menu
menu.addEventListener("onInit",lis);
This example shows how the onAddItem event can be triggered each time an item is added. In this example, the target (the menu instance name) into which the items were added is outputted as well as the items that are added:
var lis={};
lis.onAddItem=function(evt:Object){
trace("items added from "+evt.target+":");
trace(evt.ids);
}
//add listener to menu
menu.addEventListener("onAddItem",lis);
Note: The code examples above assume that your 3DMenu has an instance name of menu.
The listener method now listens for the initialization event of the 3DMenu and performs the specified action. In this example, we are simply doing a trace to the output window.