0
votes

I got this stupid glitch in the linear tween when the birds fly from left to right (i.e. sometimes they freeze).

Live : http://tli-temp.heroku.com/
Code :

package tli {

  import flash.events.TimerEvent;
  import flash.utils.Timer;
  import com.greensock.TweenMax;
  import com.greensock.easing.Linear;

public class Birds {

    private var birds:Array;

    public function Birds():void {
      birds = TLI.birds as Array;
      var i:uint = 4;
      while (i > 0) { new_bird(i); --i; }
    }

    private function new_bird(nr:uint):void {
      var b:Bird = new Bird();
      b.name = 'Bird nr.' + nr;
      b.scaleX = 0.23;
      b.scaleY = 0.23;
      b.x = -100;

      TLI.stage.addChild(b);

      birds.push(b);

      setTimeout(function():void {  tween_bird( birds[0] ); birds.shift()  }, rndm(5500, 500));
    }

    private function tween_bird(bird:Bird):void {
      bird.x = -100;
      bird.y = rndm(TLI.stage.stageHeight - TLI.sea.height - 80, 50);

      TweenMax.to( bird, rndm(55,35), {
        x: TLI.stage.stageWidth + 100, ease: Linear.easeNone,
        onComplete: tween_bird, onCompleteParams: [bird]
      });
    }

    private function rndm(max:uint, min:uint=0):uint {  return Math.floor( Math.random() * (max-min) ) + min }
}}

Anyone got an idea how I could fix this?

1
actually i had an error before any glithces: Error #2015: BitmapData Object is not valid. at flash.display::BitmapData/ctor() at flash.display::BitmapData() at tli::Sky() at TLI/init()Igor Milla
Hmm weird, I didn't have that error and I'm using a debugger player too. But thanks, I'll look into it!Icid
What be the glitch? On first look, i'd say the timer plus TweenMax is overkill. Maybe use one or the other.Ethan
Why is that overkill? And yeah, I should probably use the delay property now that I think of it.Icid
@igor-milla So, I altered my code a bit, do you still get that error?Icid

1 Answers

0
votes

This:

 var t:Timer = new Timer(wait_time, 1);

Creates a timer in the function scope. When the function goes out of scope, the timer becomes a candidate for garbage collection. It's possible the timer is garbage collected and the complete event never fires.

A setTimeout() call is safe, and probably does what you need.

Not sure if that's the problem you're seeing, but it is a problem you probably want to fix.