LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-06-2009, 05:46 PM
grebs grebs is offline
Registered User
 
Join Date: Nov 2008
Posts: 28
Rep Power: 0
grebs is on a distinguished road
Error: Error #1023: Stack overflow occurred.

i have built a space game. i am using numbers for the menu screen. when the user presses 1 i want 10 instances of a movieclip called blackhole to be added to the stage and when the user presses 2 i want 5 instances of the same movieclip to be added to the stage. This works as an easy and normal setting. However when the user presses 1 or 2 i get this error -

Error: Error #1023: Stack overflow occurred.
at spaceGameMobileMenuWorkingPublished_fla::MainTimel ine/position()
at spaceGameMobileMenuWorkingPublished_fla::MainTimel ine/position()
at spaceGameMobileMenuWorkingPublished_fla::MainTimel ine/position() etc.....

Here is my code -

Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, chooseStart);//adds an eventlistener to the stage to listen for a keyDown event
function chooseStart(evt:KeyboardEvent):void
{
    if(evt.keyCode == 49)//listens for the 1 key
    {
        openingSoundSC.stop();//plays the openingSound
        moon.visible = true;//shows the moon movieclip on the stage
        for(i = 0; i < 10; i++)//executes the for loop for 10 times
    {
        blackHole.x = Math.random() * stage.stageWidth;
        blackHole.y = Math.random() * stage.stageHeight;
        position(blackHole);
        blackHoles.push(blackHole);//stops blackholes overlapping
        blackHoles.push(moon);//stops blackholes and moon overlapping
        blackHoles.push(gameTimer_tb);//stops blackholes and gameTimer overlapping
        blackHoles.push(lives_tb);//stops blackholes and lives_tb overlapping
        blackHoles.push(spaceship_mc);//stops blackholes and spaceship_mc overlapping
        addChild(blackHole);//add the blackhole to the stage
    }
    gravity = 1;//sets the gravity to 1
    timer.start();//starts the timer
    addChild(spaceship);//adds the spaceship to the stage
    spaceship.x = 30;
    spaceship.y = 20;//positions spaceship
    removeChild(startButton);//removes startButton from stage
    removeChild(easy);//removes easy button from stage
    removeChild(hard);//removes hard button from stage
    removeChild(exit);//removes exit button from stage
    removeChild(splashScreen);//removes splashScreen from stage
    removeChild(instructionsText);//removes//instructions text from stage
    stage.removeEventListener(KeyboardEvent.KEY_DOWN, chooseStart);//removes the start event listener
    stage.removeEventListener(KeyboardEvent.KEY_DOWN, chooseHard);//removes the hard event listener
    stage.removeEventListener(KeyboardEvent.KEY_DOWN, chooseExit);//removes the exit event listener
    } 
    else if(evt.keyCode == 50)//listens for the 2 key
    {
        moon.visible = true;
        for(i = 0; i < 5; i++)//executes the for loop for 5 times
    {
        blackHole.x = Math.random() * stage.stageWidth;
        blackHole.y = Math.random() * stage.stageHeight;
        position(blackHole);
        blackHoles.push(blackHole);
        blackHoles.push(moon);
        blackHoles.push(gameTimer_tb);
        blackHoles.push(lives_tb);
        blackHoles.push(spaceship_mc);
        addChild(blackHole);
    }
    gravity = 1;
    timer.start();
    addChild(spaceship);
    spaceship.x = 30;
    spaceship.y = 20;
    removeChild(instructionsText);
    removeChild(startButton);
    removeChild(easy);
    removeChild(hard);
    removeChild(exit);
    removeChild(splashScreen);
    stage.removeEventListener(KeyboardEvent.KEY_DOWN, chooseStart);
    }
}
i know the position function keeps firing but i'm not sure how to stop it firing too many times.
Can anyone help?
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stack overflow error on only 4 class instantiations clem_c_rock Flash CS4 5 08-07-2009 09:44 AM




All times are GMT. The time now is 07:40 PM.