Skip to main content
Known Participant
May 17, 2011
Answered

Spawning Enemies to Stage in Flash AS3

  • May 17, 2011
  • 1 reply
  • 3851 views

I have the enemies appearing on my stage  and spawning accordingly.  I have the location on where I want them to  spawn. The problem is that they are spawning on the first frame of my  game which is the main menu before entering the actual playing field. Not the second frame where my game commences.

How can i go about  this?

I tried this command and it just starts the game on the second frame.

I wrote this code within my createEnemy function.

   createEnemy.start(2);

        function commenceGame():void
        {
               
                //Sliding Duck Objects
                enemy = 1000;
                enemyTimer = new Timer(1000, enemy);
                enemyStorage = new MovieClip();
                addChild(enemyStorage);
                enemyTimer.addEventListener(TimerEvent.TIMER,createEnemy);
                enemyTimer.start();
               
                cursor = new Cursor();
                addChild(cursor);
                cursor.enabled=true;
                Mouse.hide();
                stage.addEventListener(MouseEvent.MOUSE_MOVE,shiftCursor);
        }

        //Creates Enemies on the Stage
        function createEnemy(event:TimerEvent):void
        {
                var enemyAppear = new MovieClip;
                enemyAppear = new Enemy();
                enemyAppear.x = 245;
                enemyAppear.y = 285;
                enemyStorage.addChild(enemyAppear);
               
        }

          commenceGame();

Hope this is enough code of my game to determine how to go about what I request.


Thanks Casey

This topic has been closed for replies.
Correct answer Ned Murphy

If you don't want the enemiies to be generated until you are in frame 2, then put the enemy generating code in frame 2.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
May 17, 2011

If you don't want the enemiies to be generated until you are in frame 2, then put the enemy generating code in frame 2.

CaseyCCAuthor
Known Participant
May 17, 2011

Cool thanks that works perfectly appreciate it!