How do I create a button in AS3?
Hello Everyone
How do I create a button in action script 3 and handle the click event?
Thanks
Hello Everyone
How do I create a button in action script 3 and handle the click event?
Thanks
Maybe this will help you get started.
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Graphics;
var button:Sprite = new Sprite(); //Sprite to act as the button graphic.
//Set the color of the button graphic
button.graphics.beginFill(0xFFCC00);
//Set the X,Y, Width, and Height of the button graphic
button.graphics.drawRect(10, 10, 200, 60);
button.graphics.endFill(); //Apply the fill
this.addChild(button); //Add Button Sprite to stage
button.useHandCursor = true;
button.buttonMode = true;
button.mouseChildren = false;
button.addEventListener(MouseEvent.CLICK, buttonClickHandler);
function buttonClickHandler(event:MouseEvent):void
{
trace("Button clicked!");
}
Already have an account? Login
No account yet? Create an account
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.