2 Replies Latest reply: Aug 9, 2014 1:03 AM by rahex RSS

    How to stop the code adding movie clips

    rahex Community Member

      Hi,

      I have a simple code adding movie clips. On the same time the movie clips are moving along the stage.

      The first movie clip is already on the stage and the code should add additional three. The three movie clips defined with the if statements, are added correctly (to origX and origY positions).

       

      But after adding the three, it continues adding them. And not to the firstly defined x and y, but to x=0 and y=0.

      How do I stop it after the three are added?

      The code is in a separate class file.

       

      Many thanks in advance!

       

       

      public class Duck extends MovieClip

        {

             var origX: Number;

             var origY: Number;

             var i: int;

             var newDuck: part;

       

             public function Duck()

            {

                  origX = this.x;

                  origY = this.y;

                  this.addEventListener(Event.ENTER_FRAME, moveDuck);

             }

       

             function moveDuck(event: Event): void

             {

                  this.x += 0.25;

       

                  if(this.x == origX + 50)

                  {

                       addDuck();

                  }

       

                  if(this.x == origX + 75)

                  {

                       addDuck();

                  }

       

                  if(this.x == origX + 100)

                  {

                        addDuck();

                   }

             }

       

             function addDuck(): void

             {

                  newDuck = new part();

                  parent.addChild(newDuck);

                  newDuck.scaleX = 0.55;

                  newDuck.scaleY = newDuck.scaleX;

                  newDuck.x = origX;

                  newDuck.y = origY;

             }

        }