# onEnterFrame driven function not working in AS3

**URL:** https://forum.kirupa.com/t/onenterframe-driven-function-not-working-in-as3/327344
**Category:** flash
**Created:** [February 23, 2012, 4:16am UTC](https://forum.kirupa.com/t/onenterframe-driven-function-not-working-in-as3/327344 "2012-02-23T04:16:37Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![tenthrow](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@tenthrow](https://forum.kirupa.com/u/tenthrow)
#### Post date: [February 23, 2012, 4:16am UTC](https://forum.kirupa.com/t/onenterframe-driven-function-not-working-in-as3/327344/1 "2012-02-23T04:16:37Z")

</div>

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

```auto

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.

```auto
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();
    }
}

```
