Accordion.change

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX Professional 2004.

Usage

Usage 1:

var listenerObject:Object = new Object();
listenerObject.change = function(eventObject:Object) {
    // Insert your code here.
};
accordionInstance.addEventListener("change", listenerObject);

Usage 2:

on (change) {
    // Insert your code here.
}

Description

Event; broadcast to all registered listeners when the selectedIndex and selectedChild properties of an accordion change. This event is broadcast only when a user's mouse click or keypress changes the value of selectedChild or selectedIndex--not when the value is changed with ActionScript. This event is broadcast before the transition animation occurs.

Components use a dispatcher/event listener model. The Accordion component dispatches a change event when one of its buttons is clicked and the event is handled by a function (also called a handler) on a listener object (listenerObject) that you create. You call the addEventListener() method and pass it a reference to the handler as a parameter.

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.

The Accordion change event also contains two unique event object properties:

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);

Flash CS3