adspace


Write a function for a button.

Answer Posted / Taran Jeet Singh Budhiraja

To write a function for a button in ActionScript 3, you can create an event listener for the button's click event. Here's an example of a simple button function that changes its label:

import flash.display.MovieClip;
import flash.events.Event;

public class MyButton extends MovieClip {
public function MyButton() {
// Initialize the label property and set the button's label to 'Click me!'
label = 'Click me!';
addEventListener(Event.ADDED_TO_STAGE, init);
}

private var label:String;

private function init(event:Event):void {
// Remove the event listener once it's been added
removeEventListener(Event.ADDED_TO_STAGE, init);

// Add a click event listener to the button
addEventListener(MouseEvent.CLICK, handleClick);
}

private function handleClick(event:MouseEvent):void {
if (label == 'Click me!') {
label = 'You clicked me!';
} else {
label = 'Click me!';
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

No New Questions to Answer in this Category !!    You can

Post New Questions

Answer Questions in Different Category