views:

17

answers:

1

I have this class named MovingObject which extends the MovieClip class. This class will be instantianted for several times. Inside this class is a Timer that handles the speed of the objects moving. There is another class called TheStage and this is where I will instantiate MovingObject (s).

public class MovingObject extends MovieClip{
     public var tmr:Timer = new Timer(1);
     public function MovingObject(){
         tmr.addEventListener(TimerEvent.TIMER, Move);
     }
     public function StartMove():void{
         this.tmr.start();
     }
     public function ChangeSpeed(delay:Number):void{
         this.tmr.delay = delay;
     }
     public function Move(evt:TimerEvent):void{
        // some codes to make this.x and this.y change
     }
}

public class TheStage extends MovieClip{
    public var objectArray:Array = [];
    public function TheStage(){
         var x:int =0;
         var mcMoveObject;
         while (x!=10){
              mcMoveObject = new MovingObject();
              mcMoveObject.x += 10;//offset between the objects
              mcMoveObject.y += 10;//offset between the objects
              this.addChild(mcMoveObject);
              objectArray.push(mcMoveObject);
              mcMoveObject.tmr.start();
              x++;
         }
    }
    public function ChangeSpeed(delay:Number):void{//some function to change speed
        for(var chilCnt:int =0;chilCnt<objectArray.length; chilCnt++){
            objectArray[chilCnt].timer.delay = delay;
        }
    }
}

Assuming that the code is working fine (I haven't debugged it), this makes the particles to move all at once. However after several seconds of running it, the particles seem not to be moving in synchronization with each other (because their distances between seem to get nearer). I need some help to make the objects move with their distances each other evened out.

A: 
PatrickS
No I haven't tried the exact codes. Yeah, assigning the X and Y there would only cause the objects to overlap. What I meant there was there would be spaces between the objects. And about starting the objects from moving, I could do both starting the tmr and triggering the function. I forgot to use the function. It seems that in Flash, when several timers are working all at once, the objects will not move evenly.
Ranier
I know what to do now. There two solutions for this. One is to assign as static timer in MovingObject instead. When the static timer is called, this will cause all the objects to be affected. Another solution is to assign the timer instead on the TheStage class instead on the MovingObject so that there would only be one timer moving all of the objects.
Ranier