ActionScript MovieClip moves to the left, but not the right

Posted by Defcon on Stack Overflow See other posts from Stack Overflow or by Defcon
Published on 2010-04-22T01:39:28Z Indexed on 2010/04/22 1:43 UTC
Read the original article Hit count: 219

I have a stage with a movie clip with the instance name of "mc". Currently I have a code that is suppose to move the player left and right, and when the left or right key is released, the "mc" slides a little bit. The problem I'm having is that making the "mc" move to the left works, but the exact some code used for the right doesn't.

All of this code is present on the Main Stage - Frame One

//Variables

var mcSpeed:Number = 0;//MC's Current Speed
var mcJumping:Boolean = false;//if mc is Jumping
var mcFalling:Boolean = false;//if mc is Falling
var mcMoving:Boolean = false;//if mc is Moving
var mcSliding:Boolean = false;//if mc is sliding
var mcSlide:Number = 0;//Stored for use when creating slide
var mcMaxSlide:Number = 1.6;//Max Distance the object will slide.

//Player Move Function
p1Move = new Object();
p1Move = function (dir:String, maxSpeed:Number) {
 if (dir == "left" && _root.mcSpeed<maxSpeed) {
  _root.mcSpeed += .2;
  _root.mc._x -= _root.mcSpeed;
 } else if (dir == "right" && _root.mcSpeed<maxSpeed) {
  _root.mcSpeed += .2;
  _root.mc._x += _root.mcSpeed;
 } else if (dir == "left" && speed>=maxSpeed) {
  _root.mc._x -= _root.mcSpeed;
 } else if (dir == "right" && _root.mcSpeed>=maxSpeed) {
  _root.mc._x += _root.mcSpeed;
 }
}

//onEnterFrame for MC
mc.onEnterFrame = function():Void  {
 if (Key.isDown(Key.LEFT)) {
  if (_root.mcMoving == false && _root.mcSliding == false) {
   _root.mcMoving = true;
  } else if (_root.mcMoving == true && _root.mcSliding == false) {
   _root.p1Move("left",5);
  }
 } else if (!Key.isDown(Key.LEFT)) {
  if (_root.mcMoving == true && _root.mcSliding == false) {
   _root.mcSliding = true;
  } else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide<_root.mcMaxSlide) {
   _root.mcSlide += .2;
   this._x -= .2;
  } else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide>=_root.mcMaxSlide) {
   _root.mcMoving = false;
   _root.mcSliding = false;
   _root.mcSlide = 0;
   _root.mcSpeed = 0;
  }
 } else if (Key.isDown(Key.RIGHT)) {
  if (_root.mcMoving == false && _root.mcSliding == false) {
   _root.mcMoving = true;
  } else if (_root.mcMoving == true && _root.mcSliding == false) {
   _root.p1Move("right",5);
  }
 } else if (!Key.isDown(Key.RIGHT)) {
  if (_root.mcMoving == true && _root.mcSliding == false) {
   _root.mcSliding = true;
  } else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide<_root.mcMaxSpeed) {
   _root.mcSlide += .2;
   this._x += .2;
  } else if (_root.mcMoving == true && _root.mcSliding == true && _root.mcSlide>=_root.mcMax) {
   _root.mcMoving = false;
   _root.mcSliding = false;
   _root.mcSlide = 0;
   _root.mcSpeed = 0;
  }
 }
};

I just don't get why when you press the left arrow its works completely fine, but when you press the right arrow it doesn't respond. It is literally the same code.

© Stack Overflow or respective owner

Related posts about actionscript

Related posts about actionscript-2