1 Reply Latest reply on Aug 5, 2010 9:38 AM by iamhepp

    Tween onMotionFinished not calling function

    iamhepp

      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

        • 1. Re: Tween onMotionFinished not calling function
          iamhepp Level 1

          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