User Guide

52 Accordion component (Flash Professional only)
When the event is triggered, it automatically passes an event object (eventObject) to the
handler. Each event object has properties that contain information about the event. You can
use these properties to write code that handles the event. For more information, see
“EventDispatcher class” on page 499.
The Accordion change event also contains two unique event object properties:
newValue Number; the index of the child that is about to be selected.
prevValue Number; the index of the child that was previously selected.
Example
The following example uses an Accordion instance named my_acc containing three child
panels labelled “Shipping Address”, “Billing Address”, and “Payment”. The code defines a
handler called
my_accListener and passes the handler to the my_acc.addEventListener()
method as the second parameter. The event object is captured by the
change handler in the
eventObject parameter. When the change event is broadcast, a trace statement is sent to
the Output panel.
// Create new Listener object.
var my_accListener:Object = new Object();
my_accListener.change = function() {
trace("Changed to different view");
// Assign label of child panel to variable.
var selectedChild_str:String = my_acc.selectedChild.label;
// Perform action based on selected child.
switch (selectedChild_str) {
case "Shipping Address":
trace("One was selected");
break;
case "Billing Address":
trace("Two was selected");
break;
case "Payment":
trace("Three was selected");
break;
}
};
my_acc.addEventListener("change", my_accListener);