Question

I'm working on a small project in AS3, and I need to make some interface buttons. I had them as separate classes at first, but then realized that it was probably overkill, and on top of that, figured out a way to simplify the event calls by making them buttons and assigning the event dispatches to their parent.

ANYWAY,

I tried remaking them using the SimpleButton class, but I can't figure out how to give the buttons any sort of design. Every tutorial on the web uses SimpleButton to make only the most bare-bones Actionscript graphics by actually drawing them with the code (why anybody would want to do that is beyond me), and my attempt at assigning a library item to the upState:

_deletebutton = new SimpleButton();
_deletebutton.upState = mc_deleteButtonUp; <--- exists in my library

doesn't do anything.

The Adobe docs say that the various states take DisplayObjects, which mean they take Sprites and MovieClips, so you should be able to do this. Does anyone know how?

THANK YOU

Was it helpful?

Solution

+1 weltraumpirat the example in the doc generates the states by code but you can assign whatever displayObject to the different states of the button.

var btn:SimpleButton = new SimpleButton();

btn.downState      = new clipFromLibDown();
btn.overState      = new clipFromLibOver();
btn.upState        = new clipFromLibUp();
btn.hitTestState   = new clipFromLibHit();
btn.useHandCursor  = true;

addChild( btn );

assuming you have 4 states called : clipFromLibDown, clipFromLibOver ... in your library, this works

OTHER TIPS

You have to instantiate an item from your library in order to use it with ActionScript. To do this, click "Export for ActionScript" and assign a class or base class to mc_deleteButtonUp in the properties panel. Then use the new operator with the assigned class to instantiate it. You can start your button by using the example from Adobe's documentation, then change things to fit your own program.

You're probably not setting the hitTestState property of your SimpleButton instances. This property is a DisplayObject that defines where the user has to move the mouse to get mouse events on the SimpleButton. You will never see the DisplayObject that you set this to. I would suggest just using one of the DisplayObjects you are already using for another state.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/SimpleButton.html#hitTestState

Also you will need to use the new operator as weltraumpirat and nicoptere have already said.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top