ozr3n
ozr3n

Reputation: 81

AS3 : Why those compiler skip Tweenlite line?

I'm using Tweenlite and Starling in AS3. Everything is working but on last rewrite compiler just ignores Tweenlite command and just crashes with this error:

[Fault] exception, information=undefined

at com.greensock.core::Animation()[/Active/_Flash/_AS3_v12/src/com/greensock/core/Animation.as:210]

at com.greensock::TweenLite()[/Active/_Flash/_AS3_v12/src/com/greensock/TweenLite.as:445]

at com.greensock::TweenLite$/to()[/Active/_Flash/_AS3_v12/src/com/greensock/TweenLite.as:919]

this is the code where the error occurs:

private function down():void {
    TweenLite.to(square, stage.stageHeight / 200, {y: stage.stageHeight - 50, ease: Linear.easeNone});
    if (stopped){
        TweenLite.to(square, square.y / 200, {y: 50, ease: Linear.easeNone});
        stopped = !stopped;
        rRight();
    } else {
        right();
    }
}

if I remove if statement Teening happens, if I leave it everything crashes. I don't understand why would compiler skip tweening.

Here's the rest of the code that is relevant:

public class Square extends Sprite implements ISquare {

public const square:Quad = new Quad(100, 100);
private var stopped:Boolean;

public function Square() {
}

public function draw():void{
    addChild(square);
    square.pivotX = square.width / 2;
    square.pivotY = square.height / 2;
    square.x = 50;
    square.y = 50;

    stopped = new Boolean(false);
    down();
}

...

public function reverseDirection():void{
    stopped = !stopped;
    TweenLite.killTweensOf(square);
}

private function down():void {
    TweenLite.to(square, stage.stageHeight / 200, {y: stage.stageHeight - 50, ease: Linear.easeNone});

    if (stopped){
        TweenLite.to(square, square.y / 200, {y: 50, ease: Linear.easeNone});
        stopped = !stopped;
        rRight();
    } else {
        right();
    }
}

private function right():void {
    TweenLite.to(square, stage.stageWidth / 200, {x: stage.stageWidth - 50, ease: Linear.easeNone});
    if (stopped){
        TweenLite.to(square, square.x / 200, {x: 50, ease: Linear.easeNone});
        stopped = !stopped;
        rUp();
    } else {
        up();
    }
}
...

Context source: https://www.dropbox.com/sh/9x2q93o2ff1fsna/AADVJgt5nipDE1pdkgozkOc1a (Square.as)

Upvotes: 2

Views: 192

Answers (1)

Pimgd
Pimgd

Reputation: 6043

So, something is going wrong inside Tweenlite. What specifically, I don't know.

You say that when you remove the if statement, all goes well.

And that previously, everything was fine.

Given your previous questions, I posit that previously, everything was not fine. This is the first time your program is actually working. It's the first time it actually tweens and goes through all the code like you wrote it.

And looking at the code, as well as some of the decompiled code I found online, I think it's related to this:

You are not waiting for your tweens to complete.

Currently, you execute the code like this, after it has been added: (I have added comments to explain what happens)

private function down():void {
    TweenLite.to(square, stage.stageHeight / 200, {y: stage.stageHeight - 50, ease: Linear.easeNone});
    //1x tween started
    if (stopped){//I dunno where it goes, it goes A here...
        TweenLite.to(square, square.y / 200, {y: 50, ease: Linear.easeNone});//2nd tween
        stopped = !stopped;
        rRight();//and then here
    } else {//or it goes B here
        right();//and then here
    }
}

private function right():void {
    TweenLite.to(square, stage.stageWidth / 200, {x: stage.stageWidth - 50, ease: Linear.easeNone});
    //B path - 2nd tween started
    if (stopped){//idk, but
        TweenLite.to(square, square.x / 200, {x: 50, ease: Linear.easeNone});//either 3rd
        stopped = !stopped;
        rUp();//and on and on
    } else {//or
        up();//on and on anyway
    }
}

private function rRight():void {
    TweenLite.to(square, stage.stageWidth / 200, {x: stage.stageWidth - 50, ease: Linear.easeNone});
    //A path - 3rd tween started
    if (stopped){//idk which way, but
        TweenLite.to(square, square.x / 200, {x: 50, ease: Linear.easeNone});//4th
        stopped = !stopped;
        down();//and on and on
    } else {//or
        rDown();//still on and on and on
    }

}

What's happening is that you have a infinite loop, and something in Tweenlite BREAKS.

Probably that it has to process all the tweens you managed to add whilst Tweenlite was waiting for ENTER_FRAME. Looking at the documentation, it seems you can add a parameter onComplete in your third argument of your TweenLite.to call. You put a function in there, and it will get called when the tween is done. More details can be found in the documentation for onComplete.

Upvotes: 2

Related Questions