I created some button states in flash (swc), and I want to use them in a pure AS3 project. They are movie clips with class of neatButton_on and neatButton_off respectively. I call them like this:
public class neatButton extends neatModule
{
private var stateOn:neatButton_on;
private var stateOff:neatButton_off;
private var modContainer:Sprite = new Sprite();
public function neatButton()
{
addChild(modContainer);
modContainer.x = 200;
modContainer.y = 200;
stateOff = new neatButton_off();
stateOn = new neatButton_on();
modContainer.addChild(stateOn);
modContainer.addChild(stateOff);
modContainer.addEventListener(MouseEvent.MOUSE_OVER, hover);
modContainer.addEventListener(MouseEvent.MOUSE_OUT, unhover);
}
private function hover(e:MouseEvent):void
{
stateOff.visible = false;
}
private function unhover(e:MouseEvent):void
{
stateOff.visible = true;
}
}
My question is, is this the best way to do this? I’ve also used assets, especially for different states of the same item, where I’ve put everything in one movie clip and then switched frames as needed. Is one way faster than the other? is there a best practice?
I’ll share a simple class I use for creating two state image buttons. I use Tweenlite to effect a alpha tween on rollover.
You just need to send in a string that gets fed into a switch statement. This class can be used for multiples cases this way. And then to kill, simply call _imgButton.destroy() in the parent.
This class is essentially similar to yours, just with some added functionality 😉
cheers