There is a function that I use all the time written in AS2 with buttons and rollovers to create a smooth animation in and out that doesn’t relly on gotoAndPlay or gotoAndStop methods (as I have found them to be quite buggy. The AS2 code follows. I have started to write the same function in AS3, but keep getting errors when attempting to create a nested even listener for the onEnterFrame function that will drive the animation forward. How can I rewrite the AS2 function to work the same way in AS3.
This is the AS2 Code
btnBox.onRollOver = function()
{
btnBox.onEnterFrame = function() {
if(btnBox._currentframe < 11) {
btnBox.nextFrame();
} else {
delete btnBox.onEnterFrame;
}
}
}
btnBox.onRollOut = function()
{
btnBox.onEnterFrame = function() {
if (btnBox._currentframe > 1) {
btnBox.prevFrame();
} else {
delete btnBox.onEnterFrame;
}
}
}
This is what I have started with, in AS3 but can’t figure out how to finish without errors.
import flash.events.Event;
btnBox.addEventListener(MouseEvent.ROLL_OVER, BiggerBox);
btnBox.addEventListener(MouseEvent.ROLL_OUT, SmallerBox);
function BiggerBox(Event:MouseEvent):void{
trace("I hate AS3");
if (btnBox.currentFrame < btnBox.totalFrames){
btnBox.nextFrame();
}
}
function SmallerBox(Event:MouseEvent):void{
trace("I love AS3");
if (btnBox.currentFrame > 1){
btnBox.prevFrame();
}
}