5 Replies Latest reply on Apr 26, 2009 6:43 PM by Ned Murphy

    Flash Player is Running Slowly

    esplin-9466

      I am writing a program in Adobe Flash CS4 Professional. However, when I get to a certain spot in the program, Flash Player displays a message saying "A script in this movie is causing Flash Player to run slowly. If it continues to run, your computer amy become unresponsive. Do you want to abort the script?" If  I click yes, I can't play the game. If I click no, the message displays again shortly. What should I do? I have already used the "delete" statement to delete sounds in other frames. HELP!

        • 1. Re: Flash Player is Running Slowly
          Ned Murphy Adobe Community Professional & MVP

          This message is often driven by something running in an infinite loop.  You may want to check any loops you use that involve "while".  You can put a trace in to see if something is running especially more than expected.

          • 2. Re: Flash Player is Running Slowly
            esplin-9466 Level 1

            I don't have any while loops. Could it be a for loop? I inserted a trace statement into each of them, and none of those repeated infinitely.

            • 3. Re: Flash Player is Running Slowly
              Ned Murphy Adobe Community Professional & MVP

              You indicated that the problem seems to occur when you reach a certain spot in your programming.  What is going on in that portion of code?

              • 4. Re: Flash Player is Running Slowly
                esplin-9466 Level 1

                Here is the code in this frame:

                 

                stop();
                trace("Transition to Game finished. ");
                init();
                trace("Finished functions. ");

                onEnterFrame = function(){
                //See if I need to start the game music.
                if(gameMusicController > 37){
                  gameMusicController = 0;
                }
                if(gameMusicController = 0){
                  gameMusic.start();
                  trace("started game music");
                }
                gameMusicController ++;
                //Variable EARTH EAT TRASH CAN sees if earth eats the
                //trash cans or vice versa upon collision.
                eETC --;
                //If the user has no more lives, the game is over.
                if(lives = 0){
                  gotoAndPlay("gameOver");
                }
                //Now responding to keyboard input.
                if(Key.isDown(Key.DOWN)){
                  earth.dx = 0;
                  earth.dy = 1;
                }if(Key.isDown(Key.UP)){
                  earth.dx = 0;
                  earth.dy = -1;
                }if(Key.isDown(Key.LEFT)){
                  earth.dx = -1;
                  earth.dy = 0;
                }
                if(Key.isDown(Key.RIGHT)){
                  earth.dx = 1;
                  earth.dy = 0;
                }//Finished responding to keyboard input.
                }
                trace("Finished the major onEnterFrame function. ");

                earth.onEnterFrame = function(){
                earth._x += earth.dx;
                earth._y += earth.dy;
                }

                for(recycleBigNum = 1; 0 < recycleBigNum <= 9; recycleBigNum ++){
                currentRecycleBig = eval("recycleBig" + recycleBigNum);
                currentRecycleBig.onEnterFrame = function(){
                  if(earth.hitTest(currentRecycleBig)){
                   trace("Earth hit " + currentRecycleBig + ". ");
                   earth.dx = 0;
                   earth.dy = 0;
                   question.gotoAndStop(Frame (Math.ceil((Math.random) * 30)));
                   question._x = ((Stage.width) / 2);
                   question._y = ((Stage.height) / 2);
                  }
                }
                }

                for(trashCanNum = 1; trashCanNum < 4; trashCanNum ++){
                currentTrashCan = eval("trashCan" + trashCanNum);
                //Check to see if earth hits a trash can.
                currentTrashCan.onEnterFrame = function(){
                  if(earth.hitTest(currentTrashCan)){
                   if(eETC < 0){
                    currentTrashCan._x = 220 + ((trashCanNum - 1) * 44.5);
                    currentTrashCan._y = 247;
                    lives --;
                    trace("lost a life");
                   }if(eETC > 0){
                    currentTrashCan.removeMovieClip();
                    ateTrashCanSound.start();
                    trace("ate a trash can");
                   }
                  }
                }
                }

                trashCan1.onEnterFrame = function(){
                if(earth._y < trashCan1._y){
                  if(eETC > 0){
                   trashCan1.dy = 1;
                  }else{
                   trashCan1.dy = -1;
                  }
                }if(earth._y > trashCan1._y){
                  if(eETC > 0){
                   trashCan1.dy = -1;
                  }else{
                   trashCan1.dy = 1;
                  }
                }
                this._x = earth._x;
                this._y += this.dy;
                }
                trashCan2.onEnterFrame = function(){
                if(earth._x < trashCan2._x){
                  if(eETC > 0){
                   trashCan2.dx = 1;
                  }else{
                   trashCan2.dx = -1;
                  }
                }if(earth._x > trashCan2._x){
                  if(eETC > 0){
                   trashCan2.dx = -1;
                  }else{
                   trashCan2.dx = 1;
                  }
                }
                this._y = earth._y;
                this._x += this.dx;
                }
                trashCan3.onEnterFrame = function(){
                if(earth._y < trashCan3._y){
                  trashCan3.dy = -1;
                }if(earth._y > trashCan3._y){
                  trashCan3.dy = 1;
                }
                this._x = (earth._x + trashCan2._x) / 2;
                this._y += this.dy;
                }

                function init(){
                trace("Running function init()");
                eETC = 0;
                question.stop();
                //Give player 5 lives.
                lives = 5;
                Mouse.hide();
                earth.dx = 0;
                earth.dy = 0;
                trashCanW = 44.5 / 2;
                trashCanH = 74.8 / 2;
                i = 0;
                _root.userScore = 0;
                _root.recycleSmallLeft = 0;
                //Creating trash cans
                for(trashCanNum = 1; trashCanNum < 4; trashCanNum ++){
                  _root.attachMovie("trashCan", "trashCan" + trashCanNum, 200 + trashCanNum);
                  trace("Made trash can " + trashCanNum + "! Yeah! ");
                  currentTrashCan = eval("trashCan" + trashCanNum);
                  currentTrashCan._x = 220 + ((trashCanNum - 1) * 44.5);
                  currentTrashCan._y = 247;
                }//All trash cans' position defined.
                //Creating small recycling symbols.
                //Create Arvind's game music.
                //Add sound to game
                gameMusic = new Sound();
                gameMusic.attachSound("gameMusic");
                trace("Made game music. ");
                gameMusicController = 0;
                //About the previous line:
                //I want the music to repeat every 37 seconds (it is 41
                //seconds long, byut Arvind put extra space in the back)
                //so I make a variable.
                //Note to self: finish trash can sound
                ateTrashCanSound = new Sound();
                ateTrashCanSound.attachSound("ateTrashCan");
                trace("Made ate trash can sound. ");
                }

                 

                The output window says:

                 

                Spacebar pressed.
                Spacebar pressed.
                We made it to the start screen!
                Transition to Game finished.
                Running function init()
                Made trash can 1! Yeah!
                Made trash can 2! Yeah!
                Made trash can 3! Yeah!
                Made game music.
                Made ate trash can sound.
                Finished functions.
                Finished the major onEnterFrame function.

                • 5. Re: Flash Player is Running Slowly
                  Ned Murphy Adobe Community Professional & MVP

                  There's a little much to go thru to try to track down where the problem might be, but here's a few things you might do to clean things up...

                   

                  1) if(anything = something)....  incorrect syntax, use == for comparisons

                   

                  2) for comparisons that you string along...

                   

                  if(...){

                   

                  }if(){

                   

                  }

                   

                  place an else before the second if

                   

                  3) look to condense all of your various enterframe code into one enterframe block instead of assigning multiple times as a function for different movieclips