1 Reply Latest reply on May 24, 2010 10:55 PM by JaxNa

    Stop ball depending upon speed

    JaxNa Level 1

      Hi,

       

      I want to stop ball depending on the speed.

      when i will set the ball speed that time i want to move this ball on this speed.

       

      Here is my code...

       

      var speed:Number = 0;

      var intervalIDLine:Number;
      right_btn.onPress = function() {
          if (arrow_mc._rotation<0) {
              arrow_mc._rotation = arrow_mc._rotation+5;
          }
          intervalIDLine = setInterval(setAngleRight, 200);
      };
      right_btn.onRelease = function() {
          clearInterval(intervalIDLine);
      };
      function setAngleRight() {
          if (arrow_mc._rotation<0) {
              arrow_mc._rotation = arrow_mc._rotation+5;
          }
      }
      var intervalLeftID:Number;
      left_btn.onPress = function() {
          if (arrow_mc._rotation>=-172.094131469727) {
              arrow_mc._rotation = arrow_mc._rotation-5;
          }
          intervalLeftID = setInterval(setAngleLeft, 200);
      };
      left_btn.onRelease = function() {
          clearInterval(intervalLeftID);
      };
      function setAngleLeft() {
          if (arrow_mc._rotation>=-172.094131469727) {
              arrow_mc._rotation = arrow_mc._rotation-5;
          }
      }

      function onEnterFrame() {

      for (i in balls) {
              ball = balls[i];
              ball._x += Math.cos(ball._rotation*Math.PI/180)*speed;
              ball._y += Math.sin(ball._rotation*Math.PI/180)*speed;
              ball._xscale -= 5.1;
              ball._yscale -= 5.1;
              if (ball._y<100 && _global.golerAni == false) {
                  goler_mc.gotoAndPlay("f3");
                  _global.golerAni = true;
              }
              if (ball._x<0 || ball._x>Stage.width || ball._y<=0 || ball._y>Stage.height) {
                  ball.removeMovieClip();
                  balls.splice(i,1);
                  press_btn.enabled = true;
                  display_ball._visible = true;
              }
          }

      }

      var ballId:Number;
      function ballthrough() {
          if (speed<20) {
              speed = speed+1;
              trace("speed="+speed);
          }
      }
      press_btn.onPress = function() {
          speed_mc.gotoAndPlay(2);
          if (speed<=20) {
              ballId = setInterval(ballthrough, 200);
          }
          if (speed>1) {
              speed = 1;
          }
      };
      press_btn.onRelease = function() {
          if (speed<=20) {
              speed_mc.stop();
          }
          clearInterval(ballId);
          var ball:MovieClip = _root.attachMovie("ball", "ball_", _root.getNextHighestDepth());
          ball.swapDepths(10);
          ball._x = arrow_mc._x;
          ball._y = arrow_mc._y;
          ball._rotation = arrow_mc._rotation;
          balls.push(ball);
          display_ball._visible = false;
          press_btn.enabled = false;

       

      };

       

      Thanks,

      JaxNa