Jump to content
Search Community

Inertial scroller - onComplete doesn't fire.

jtvalles test
Moderator Tag

Recommended Posts

I have some code that scrolls a movieClip. The problem is I cannot get the onComplete to fire and remove the listener. It will fire when the clip reaches its bounds but not any time in between.

 

Does my code prevent the tween from completing?

 


import com.greensock.*;
import flash.display.MovieClip;

var mc:Sprite = new Sprite();
mc.graphics.beginGradientFill(GradientType.LINEAR,
[0x666666,0xfff000],[0.9,0.1],[0,255],
new Matrix(0,-1,1,0,height,0));
mc.graphics.drawRect(225, 50, 100, 300)
addChild(mc);
var destination:Point=new Point();
var dragging:Boolean=false;
var speed:Number=20;
var offset:Point=new Point();
var topLimit:Number = 0 - ( mc.height - (stage.height-50) );
var bottomLimit:Number = 120;

mc.addEventListener(MouseEvent.MOUSE_DOWN,startdrag, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP,stopdrag, false, 0, true);

function startdrag(e:MouseEvent):void{

  offset.y=mc.mouseY*mc.scaleY;
  dragging=true;
  mc.addEventListener(Event.ENTER_FRAME,followmouse, false, 0, true);

}

function stopdrag(e:MouseEvent):void{
  dragging=false;
}

function followmouse(e:Event):void{

  if(dragging){
  destination.y=mouseY;
  }

  TweenLite.to(mc, 2, {y:mc.y-=(mc.y-(destination.y-offset.y))/speed, onComplete:removeEFListener});

  if(mc.y > bottomLimit){
  mc.removeEventListener(Event.ENTER_FRAME,followmouse);
TweenLite.to(mc, .6, {y:bottomLimit});
trace('removedBottom');
  }
  if(mc.y<topLimit){
 TweenLite.to(mc, .6, {y:topLimit});
mc.removeEventListener(Event.ENTER_FRAME,followmouse);
trace('removedTop');
  }

}

function removeEFListener():void{
mc.removeEventListener(Event.ENTER_FRAME,followmouse);
trace('removedEL');
}

 

Note: This code is repurposed. I lost the source for the original code and gladly give credit where its due - so if its yours, thanks and good job.

Link to comment
Share on other sites

from your code it appears that as soon as your drag beyond bottomLimit or topLimit you are creating new tweens that don't have an onComplete and most likely they are overwriting the tween that did have the onComplete.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...