9 Replies Latest reply on Jan 28, 2007 6:37 PM by Jimmathy

    Terminating ActionScript

    Jimmathy Level 1
      What line of coding would terminate all action script in that frame?
        • 1. Re: Terminating ActionScript
          kglad Adobe Community Professional & MVP
          _level0.removeMovieClip();

          but you probably won't want to do that. what are you trying to do?
          • 2. Re: Terminating ActionScript
            Jimmathy Level 1
            i have 3 frames(menu, game, and gameover). The 1st frame in "game" generates squirrels and rocks that slide left to right for the car to hit. when the car hits a rock it blows up and flys off screen. This then triggers it to wait a few seconds(to let all the squirrels/ rocks clear(b/c i dont know how to do it otherwise)) and then move to the "gameover" scene. In the gameover scene theres a button that leads to the 1st fram of the "game" where all the action script is located. Here is where it all hits the fan :P. after a few seconds of sitting in the game scene it returns to the "gameover" scene and generates squirrels and rocks at random speeds(this is nowhere specified in my script though). Every time u try to press the button to start a new game it flips to "game" then back and generated the objects randomly...
            that wasthe only thing i could think of to try, if u have suggestions that would be helpful; heres the code i have on the frame in "game":
            stop();
            z=1000;
            q=1;
            w=1;
            i=1;
            score = 0;
            k=attachMovie("car","car", 500);
            k._x = 70;
            k._y = 200;
            i1=setInterval(check,10);
            i2=setInterval(drive, 25);
            i3=setInterval(kill,z);
            i4=setInterval(lvlup,2000);
            i5=setInterval(rocks,2600);
            function check(){
            if(i > 400){
            i=1}
            if(q >400){
            q=1}
            if(w >400){
            w=1;}
            if(car._x<0){
            car.removeMovieClip();
            setInterval(GO,2000);
            clearInterval(i1);
            clearInterval(i2);
            clearInterval(i3);
            clearInterval(i4);
            clearInterval(i5);
            }}
            function drive(){
            if(Key.isDown(Key.UP)){
            _root.car._y -= 4;
            _root.car._rotation = -15;
            _root.holder._x = _root.car._x;
            _root.holder._y = _root.car._y;
            }
            else if(Key.isDown(Key.DOWN)){
            _root.car._y += 4;
            _root.car._rotation = 15;
            _root.holder._x = _root.car._x;
            _root.holder._y = _root.car._y;
            }
            else{_root.car._rotation = 0;
            }}
            function kill(){
            rk=_root.attachMovie("squirrel", "squirrel"+i, i);
            i++;
            rk._rotation = Math.random()*360;
            rk._y = Math.random()*325;
            rk._x = 545;
            rk.speed=6;
            rk.movel=setInterval(moveF,30,rk);
            }
            function moveF(mc){
            mc._x -= mc.speed;
            if(mc.hitTest(_root.car)){
            mc.gotoAndStop("death");}
            if(mc._x < 0){
            mc.removeMovieClip();
            }
            }
            function lvlup(){
            z = 10;
            }
            function rocks(){
            rok=_root.attachMovie("rock", "rock"+w, w);
            w++;
            rok._rotation = Math.random()*360;
            rok._y = Math.random()*300;
            rok._x = 545;
            rok.speed=6;
            rok.movel=setInterval(moveRoc,30,rok);
            }
            function moveRoc(mb){
            mb._x -= mb.speed;
            if(mb.hitTest(_root.car)){
            car.gotoAndStop("boom");
            car.speed= 6;
            car.moved=setInterval(cardied,30,car);}
            if(mb._x < -5){
            mb.removeMovieClip();
            }
            }
            function cardied(){
            car._x -= car.speed;}
            function GO(){
            gotoAndStop("gameover");
            }
            • 3. Re: Terminating ActionScript
              Jimmathy Level 1
              Oh! and that clear interval stuff i have there from a previous attempt of trying to fix this.
              • 4. Re: Terminating ActionScript
                kglad Adobe Community Professional & MVP
                1. clear your intervals before you remove those movieclips that have intervals defined.

                in your GO() function:

                2. clear all your intervals before executing that gotoAndStop()
                3. remove all the movieclips created in frame 1 before you execute your gotoAndStop().
                • 5. Re: Terminating ActionScript
                  Jimmathy Level 1
                  Okay, makes sense, but when i tried all that clear interval stuff up there it didnt work... Why is that and how do i fix it?
                  • 6. Re: Terminating ActionScript
                    kglad Adobe Community Professional & MVP
                    it didn't work because you didn't do it correctly and you fix it by doing it correctly.

                    for specific help, post your updated code.
                    • 7. Re: Terminating ActionScript
                      Jimmathy Level 1
                      stop();
                      z=1000;
                      q=1;
                      w=1;
                      i=1;
                      score = 0;
                      k=attachMovie("car","car", 500);
                      k._x = 70;
                      k._y = 200;
                      setInterval(check,10);
                      setInterval(drive, 25);
                      setInterval(kill,z);
                      setInterval(lvlup,2000);
                      setInterval(rocks,2600);
                      function check(){
                      if(i > 400){
                      i=1}
                      if(q >400){
                      q=1}
                      if(w >400){
                      w=1;}
                      if(car._x<0){
                      car.removeMovieClip();
                      setInterval(GO,2000);
                      }}
                      function drive(){
                      if(Key.isDown(Key.UP)){
                      _root.car._y -= 4;
                      _root.car._rotation = -15;
                      _root.holder._x = _root.car._x;
                      _root.holder._y = _root.car._y;
                      }
                      else if(Key.isDown(Key.DOWN)){
                      _root.car._y += 4;
                      _root.car._rotation = 15;
                      _root.holder._x = _root.car._x;
                      _root.holder._y = _root.car._y;
                      }
                      else{_root.car._rotation = 0;
                      }}
                      function kill(){
                      rk=_root.attachMovie("squirrel", "squirrel"+i, i);
                      i++;
                      rk._rotation = Math.random()*360;
                      rk._y = Math.random()*325;
                      rk._x = 545;
                      rk.speed=6;
                      rk.movel=setInterval(moveF,30,rk);
                      }
                      function moveF(mc){
                      mc._x -= mc.speed;
                      if(mc.hitTest(_root.car)){
                      mc.gotoAndStop("death");}
                      if(mc._x < 0){
                      mc.removeMovieClip();
                      }
                      }
                      function lvlup(){
                      z = 10;
                      }
                      function rocks(){
                      rok=_root.attachMovie("rock", "rock"+w, w);
                      w++;
                      rok._rotation = Math.random()*360;
                      rok._y = Math.random()*300;
                      rok._x = 545;
                      rok.speed=6;
                      rok.movel=setInterval(moveRoc,30,rok);
                      }
                      function moveRoc(mb){
                      mb._x -= mb.speed;
                      if(mb.hitTest(_root.car)){
                      car.gotoAndStop("boom");
                      car.speed= 6;
                      car.moved=setInterval(cardied,30,car);}
                      if(mb._x < -5){
                      mb.removeMovieClip();
                      }
                      }
                      function cardied(){
                      car._x -= car.speed;}
                      function GO(){
                      gotoAndStop("gameover");
                      }

                      here you go, im completely lost on this one...
                      • 8. Re: Terminating ActionScript
                        kglad Adobe Community Professional & MVP
                        test this to see if it gets all the intervals.

                        • 9. Re: Terminating ActionScript
                          Jimmathy Level 1
                          it sort of works. When u get the gameover the ones already on the screen dont dissappear. then when you restart the game via a button that "gotoAndStop"s at the "game" frame the rocks and squirrels are generated at about twice the speed. Other than that it worked.