Write a function for a button.



Write a function for a button...

Answer / 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

More Flash Action Scripting Interview Questions

what is not a benefit of using macromedias pre-built ui components? : Adobe flash

1 Answers  


in general, non-mp3 digital audio destined to be imported into the flash mx authoring environment should first be compressed how much? : Adobe flash

1 Answers  


Describe changewatcher.watch.

1 Answers  


How can we goto next Scene by giving code on a button inside a movie clip. in short. =>Scene 1. ====>MovieClip ======>Button [ on(release) { gotoAndPlay("Scene 2", 1); } ] =>Scene 2. This thing is not working. Please tell me the answer of how to goto next scene from this scene 1.

4 Answers   ABC,


I shoot underwater with a ttl strobe that does not allow you to set flash exposure compensation. How do I set fill flash with this set up? : Adobe flash

1 Answers  


who can view flash? : Adobe flash

1 Answers  


How to make synchronous data calls in actionscript?

1 Answers  


what is the purpose of the break statement? : Adobe flash

1 Answers  


How to start a graphic animation at a specific frame?

1 Answers  


Explain what does the void function and object contain in actionscript?

1 Answers  


which two file formats can be imported into a swf file at runtime? : Adobe flash

1 Answers  


What is meant by vector graphic animation?

1 Answers  


Categories