Skip to main content
Participating Frequently
August 5, 2010
Question

Tween onMotionFinished not calling function

  • August 5, 2010
  • 1 reply
  • 338 views

My problem is  my redrawMenu() function is not being called when onMotionFinished() is called. Any  ideas on what I am doing wrong??

****************************** MY CLASS ******************************
import fl.transitions.*;
import mx.transitions.Tween;

class skitter.view.MainMenuView extends UIObject {

private var sliderTween

public function MainMenuView(target:MovieClip, depth:Number){

...constructor code...

}

/** Animate Main Menu **/
    private function slideMenuItems(dir:Number):Void{
       var newLoc:Number;
        //To Make Sure Direction Calls Don't Call This Again Until Animation is Complete
        failSafe = true;
       
        // Move the Indicated Direction
        switch( dir ){
            case 1:
                // Set New Slide Amount
                newLoc = sliderStage._x + (mItemsArray[mItemsArray.length-1].getWidth() + offset);
                // Move the Stage
                 sliderTween = new Tween(sliderStage, "_x",  mx.transitions.easing.None.easeInOut, sliderStage._x, newLoc, speed,  true);
                break;
            case 2:
                // Set New Slide Amount
                newLoc = sliderStage._x - (mItemsArray[0].getWidth() + offset);
                // Move the Stage
                 sliderTween = new Tween(sliderStage, "_x",  mx.transitions.easing.None.easeInOut, sliderStage._x, newLoc, speed,  true);
               break;
            default :
                  break;
        }
       
        sliderTween.onMotionFinished = function() {
            trace("CALL REDRAW FUNCTION")
            Delegate.create(this, redrawMenu( dir ));
            //redrawMenu( dir );
        }
    } // END slideMenuItems()
   
    /** Redraw Items on sliderStage**/
    private function redrawMenu( dir:Number ):Void{
        trace("\t** REDRAW CALLED");

        ...code to draw items...


        failSafe = false;
    }

} // END CLASS

This topic has been closed for replies.

1 reply

iamheppAuthor
Participating Frequently
August 5, 2010

I found a snippet from Scott Morgan that solved my problem by creating a modification of the create function of the Delegate class.

sliderTween.onMotionFinished = DelegateCreate(this,redrawMenu,[dir] );

function DelegateCreate(t:Object, f:Function,args:Array):Function{
        return function():Void{
            if ((args == undefined) || (args == null))
                args=[]
                var _newArgs:Array = args.concat(arguments);
                f.apply(t, args);
        };
    }

CHEERS