views:

288

answers:

3

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});
            }
}
+1  A: 

hi Hwang,

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.

dome
i did try the way before, but I'm not sure is it because I'm using public static for that function, it returns me 1120: Access of undefined property changePageStatus.
Hwang
the solution for your problem is in another answer, danjp wrote the function inline so you can call it inside the static function.
dome
this answer is better in terms of readability and standards
danjp
+1  A: 

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

danjp
as matter of fact I think your answer is the best atm cause the tween is inside a static function it can't access other functions.
dome
A: 

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
}
Hwang