Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Button with only code AS3

I feel like something like this exists but how would I create a button in only action script 3 code? I mean without making a shape and converting it to a button symbol or something. It would probably make it easier to only work in FlashDevelop.

like image 357
Danny Swan Avatar asked Apr 30 '13 02:04

Danny Swan


1 Answers

You can use the SimpleButton class or roll your own using the Sprite class. Then you can draw anything or use any image as the button and it's over, down and default states.

For example a simple button can be like this :

var goButton:SimpleButton = new SimpleButton();

var myButtonSprite:Sprite = new Sprite();
myButtonSprite.graphics.lineStyle(1, 0x555555);
myButtonSprite.graphics.beginFill(0xff000,1);
myButtonSprite.graphics.drawRect(0,0,200,30);
myButtonSprite.graphics.endFill();

goButton.overState = goButton.downState = goButton.upState = goButton.hitTestState = myButtonSprite;
addChild(goButton);

You can have different display objects for each state of the button or you can attach bitmaps instead of sprites.

like image 85
Barış Uşaklı Avatar answered Oct 23 '22 07:10

Barış Uşaklı