AS3 - Dynamically added Tweens stop suddenly

I’m developing a mobile project with Flash Builder, and I’m having some issues with the Tween Class… It works just fine for some time, but then, all of the sudden, it just stops working.

The game emulates an “under the sea” scene, so, one of the things I have is a “bubbly” background, and it works just fine for some time, and then, all of the sudden, all the tweens stop at the same time (including some tweens that are in other classes). Any thoughts on why this could happen? I’m adding the code of the background bubbles to see if you get why this could be behaving so oddly.

public class BurbujasBack extends Sprite
{
    public var timer:Timer = new Timer(200,0);
    public var burbujasMaximas:int = 25;
    public static var burbujasActuales:int = 0;
    public function BurbujasBack()
    {
        x=Diversion_bajo_el_agua.ancho_st/2;
        y=Diversion_bajo_el_agua.alto_st;
        timer.addEventListener(TimerEvent.TIMER,_nuevaBubble);
        timer.start();
    }
    private function _nuevaBubble(e:TimerEvent):void {
        var add:Boolean = (Math.random() > .5) ? true : false;
        if (add==true) {
            if(burbujasActuales < burbujasMaximas) {
                trace("agrega una burbuja");
                var burbuja:BurbujaChica = new BurbujaChica();
                addChild(burbuja);
                burbujasActuales++;
            }
        }
    }
}
And

public class BurbujaChica extends Sprite
{
    public var velocidad:Number = Math.random();
    public var escala:Number = Math.random()*.5+.5;
    public var tiempoMaximo:int = 3;
    public var posX:Number = Math.random()*Diversion_bajo_el_agua.ancho_st;
    public function BurbujaChica()
    {
        x = posX
        var burbuja:Burbuja_ = new Burbuja_();
        burbuja.scaleX = burbuja.scaleY = escala;
        var desde:Number = burbuja.height/2;
        var hasta:Number = -Diversion_bajo_el_agua.alto_st-burbuja.height/2;
        trace("va desde "+desde+" hasta "+hasta);
        var tw:Tween = new Tween(burbuja,"y",Regular.easeIn,desde,hasta,(velocidad*tiempoMaximo)+5,true);
        tw.addEventListener(TweenEvent.MOTION_FINISH,_chauBurbuja);
        addChild(burbuja);
    }
    private function _chauBurbuja(e:TweenEvent):void {
        this.parent.removeChild(this);
        BurbujasBack.burbujasActuales--;
    }
} 

Thanks in advance!
Sarahjohn

This topic was automatically closed after 70 days. New replies are no longer allowed.