TweenLite onComplete fired instantly?
After I finish a tween, I would like to change my variables, then only my mouse movement would have start to run some functions, but it seems like the onComplete function fired immediately messing all the things out. Isnt't that onComplete function will only run after an action is done? Any other way to like after running the Tween.to line of code, only it will ran the 2nd line changing a variable?
stage.addEventListener(MouseEvent.MOUSE_MOVE, movevC);
public static function showSection(obj:DisplayObject):void {;
var sect2X=((obj.stage.stageWidth/2)+(obj.stage.stageWidth/4))+lg.width;
var sect2Y=((obj.stage.stageHeight/2)-(obj.stage.stageHeight/4))+lg.height;
switch (obj.name) {
case "section2" :
//onComplete run instantly??
TweenLite.to(vC, 10, {x:sect2X, y:sect2Y, rotation:0,ease:Elastic.easeInOut, onComplete:currentPage=2});
/*if ((vC.x=sect2X)&&(vC.y=sect2Y)) {
currentPage=2;开发者_如何学运维
}*/
break;
}
}
private function movevC(event:MouseEvent):void {
if (currentPage==2) {
TweenLite.to(vC, 2, {x:mouseX, y:mouseY});
}
}
onComplete should be a reference to a function i.e. the name what you need to to is something like this
TweenLite.to(vC, 10, {x:sect2X, y:sect2Y, rotation:0,ease:Elastic.easeInOut, onComplete:function(){currentPage=2}});
or even better, define a function that isn't 'inline' and then reference this
onComplete expects a function, so it would work if you put the currentPage=2
inside a function and put the function name inside onComplete.
like:
TweenLite.to(vC, 10, {x:sect2X, y:sect2Y, rotation:0,ease:Elastic.easeInOut, onComplete: changePageStatus});
private function changePageStatus ():void {
currentPage = 2
}
You could also write the function directly into the Tween call, but get's messier.
below is the solution i came up with, doesn't seems so perfect :/
TweenLite.to(vC, 2, {x:sect2X, y:sect2Y, rotation:0,ease:Elastic.easeInOut});
currentPage=2;
break;
if ((vC.x==sect2X)&&(vC.y==sect2Y)&&(currentPage==2)) {
currentPage=21;
} else if (currentPage==21) {
run something
}
精彩评论