User Guide
Using the Button component 93
3. In the first frame of the main timeline, add the following ActionScript to the Actions panel
to create a Button instance:
this.createClassObject(mx.containers.Accordion, "my_acc", 0);
my_acc.move(10, 40);
my_acc.createChild(mx.core.View, "panelOne", {label: "Panel One"});
my_acc.createChild(mx.core.View, "panelTwo", {label: "Panel Two"});
this.createClassObject(mx.controls.Button, "panelOne_button", 10,
{label:"Panel One"});
panelOne_button.move(10, 10);
this.createClassObject(mx.controls.Button, "panelTwo_button", 20,
{label:"Panel Two"});
panelTwo_button.move(120, 10);
This process uses the method UIObject.createClassObject() to create the Button and
Accordion instances. Then, the code uses the method
UIObject.move() to position the
instances.
4. Now, add the following ActionScript to create event listeners and event handler functions:
// Create Handler for the button event.
function changePanel(evt_obj:Object):Void {
// Change Accordion view depending on button selected.
switch (evt_obj.target._name) {
case "panelOne_button" :
my_acc.selectedIndex = 0;
break;
case "panelTwo_button" :
my_acc.selectedIndex = 1;
break;
}
}
// Add Listeners for the buttons.
panelOne_button.addEventListener("click", changePanel);
panelTwo_button.addEventListener("click", changePanel);
This process uses the method EventDispatcher.addEventListener() with a custom
function to handle the events.
5. Select Control > Test Movie.
6. When you click a button, the Accordion changes the current panel.