Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to stop the code adding movie clips

Community Beginner ,
Aug 08, 2014 Aug 08, 2014

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;

       }

  }

TOPICS
ActionScript
233
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 08, 2014 Aug 08, 2014

You function Duck() instanciates an enterFrame function that actually creates the duck instances on the stage. Once begun, there is nothing telling it to stop creating new ducks. You might want to add a for loop that counts up to the number of ducks that you want and then kills the enterframe function. I don't know why your x and y values are resetting to 0.

Translate
LEGEND ,
Aug 08, 2014 Aug 08, 2014

You function Duck() instanciates an enterFrame function that actually creates the duck instances on the stage. Once begun, there is nothing telling it to stop creating new ducks. You might want to add a for loop that counts up to the number of ducks that you want and then kills the enterframe function. I don't know why your x and y values are resetting to 0.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 09, 2014 Aug 09, 2014
LATEST

Thank you Rob for your comment.

I finally separated the code between timeline and class file and got it working this way.

The original thought to do it all in a class file was above my knowledge level.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines