Flash CS3 Documentation |
|||
| ActionScript 2.0 Components Language Reference > Button component > Using the Button component > Creating an application with the Button component | |||
The following procedure explains how to add a Button component to an application while authoring. In this example, the button displays a message when you click it.
To use an icon, there must be a movie clip or graphic symbol in the library with a linkage identifier to use as the icon parameter. In this example, the linkage identifier is BtnIcon.
toggle property to true.
function clicked(){
trace("You clicked the button!");
}
my_button.addEventListener("click", clicked);
The last line of code calls a clicked event handler function for the "click" event. This uses the method EventDispatcher.addEventListener() with a custom function to handle the event.
This adds the component to the library, but doesn't make it visible in the application.
this.createClassObject(mx.controls.Button, "my_button", 10, {label:"Click me"});
my_button.move(20, 20);
The method UIObject.createClassObject() is used to create the Button instance named my_button and specify a label property. Then, the code uses the method UIObject.move() to position the button.
function clicked() {
trace("You clicked the button!");
}
my_button.addEventListener("click", clicked);
This uses the method EventDispatcher.addEventListener() with a custom function to handle the event.
As you use the Button component with other components, you can create more sophisticated event handler functions. In this example, the "click" event causes the Accordion component to change the display of the panels.
This adds the component to the library, but doesn't make it visible in the application.
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.
// 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.
Flash CS3
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00002581.html
Comments
badgirl_1 said on Oct 4, 2007 at 9:01 PM :