6

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.

1 Answer 1

13

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks! I gave my simplebutton a height, width, x and y. it's known as private var goButton:SimpleButton = new SimpleButton(); it doesn't show on the stage though, how could I give it a background color or border?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.