If you want to have better looking animations in buttons, you don't use a Button, you use a MovieClip.
This means that you'll have to use some code to control the MovieClip. Play it forwards on mouse over, play it backwards on mouse out.
Here's the code to achieve this in ActionScript 3:
Actionscript:
-
anim_mc.stop();
-
-
anim_mc.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
-
anim_mc.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
-
anim_mc.addEventListener(MouseEvent.CLICK, onClick);
-
-
anim_mc.buttonMode = true;
-
anim_mc.mouseChildren = false;
-
-
function onClick(e:MouseEvent):void
-
{
-
trace("click");
-
}
-
-
function onMouseOver(e:MouseEvent):void
-
{
-
var mc:MovieClip = MovieClip(e.currentTarget);
-
-
mc.removeEventListener(Event.ENTER_FRAME, rewind);
-
-
mc.play();
-
mc.addEventListener(Event.ENTER_FRAME, advance);
-
}
-
-
function onMouseOut(e:MouseEvent):void
-
{
-
var mc:MovieClip = MovieClip(e.currentTarget);
-
-
mc.removeEventListener(Event.ENTER_FRAME, advance);
-
-
mc.prevFrame();
-
mc.addEventListener(Event.ENTER_FRAME, rewind);
-
}
-
-
function advance(e:Event):void
-
{
-
var mc:MovieClip = MovieClip(e.currentTarget);
-
-
if (mc.currentFrame == mc.totalFrames)
-
{
-
mc.stop();
-
mc.removeEventListener(Event.ENTER_FRAME, advance);
-
}
-
}
-
-
function rewind(e:Event):void
-
{
-
var mc:MovieClip = MovieClip(e.currentTarget);
-
-
if (mc.currentFrame == 1)
-
{
-
mc.stop();
-
mc.removeEventListener(Event.ENTER_FRAME, rewind);
-
}
-
else
-
{
-
mc.prevFrame();
-
}
-
}
The first swf file has more than one button, so it uses a Class file to simplify the process (it's available for download).
In case you're still stuck with AS2 for some reason, here's the equivalent code:
Actionscript:
-
anim_mc.stop ();
-
-
anim_mc.onRollOver = function ():Void
-
{
-
if (this._currentframe <this._totalframes)
-
{
-
this.play ();
-
-
this.onEnterFrame = function ()
-
{
-
if (this._currentframe == this._totalframes)
-
{
-
this.stop ();
-
delete this.onEnterFrame;
-
}
-
};
-
}
-
};
-
-
anim_mc.onRollOut = function ():Void
-
{
-
if (this._currentframe> 1)
-
{
-
this.prevFrame ();
-
-
this.onEnterFrame = function ()
-
{
-
this.prevFrame ();
-
if (this._currentframe == 1)
-
{
-
delete this.onEnterFrame;
-
}
-
};
-
}
-
};
-
-
anim_mc.onMouseDown = function ():Void
-
{
-
trace ("click");
-
};
You can download all the files here.