# Can't get gotoAndStop(); to work

**URL:** https://forum.kirupa.com/t/cant-get-gotoandstop-to-work/328715
**Category:** flash
**Created:** [June 9, 2012, 5:08am UTC](https://forum.kirupa.com/t/cant-get-gotoandstop-to-work/328715 "2012-06-09T05:08:32Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Ragnoroct](https://avatars.discourse-cdn.com/v4/letter/r/f07891/32.png) [@Ragnoroct](https://forum.kirupa.com/u/Ragnoroct)
#### Post date: [June 9, 2012, 5:08am UTC](https://forum.kirupa.com/t/cant-get-gotoandstop-to-work/328715/1 "2012-06-09T05:08:32Z")

</div>

I have a fla file with a movieclip that has two frames. I try to change the movieclips frame by gotoAndStop through the as file but it doesn’t work. No error it just doesn’t do anything.

fla file code on first(only one frame)

```auto
import com.mygame.dodge.Dodge;
var classDodge:Dodge = new Dodge();
addChild(classDodge);

```

as code

```auto

	public class Dodge extends MovieClip
	{
		private var mcBob:Bob;
		private var mcStartButton:StartButton;

		static const mcBobDX = 200;
		//stride var
		private var makeStride:uint = 1;
		//used to move char
		private var leftArrow:Boolean = false;
		private var rightArrow:Boolean = false;
		private var upArrow:Boolean = false;
		private var bottomArrow:Boolean = false;
		
		

		public var lastTime:int;

		private var mcBobX:Number = 263;
		private var mcBobY:Number = 199;
		
		var myTimer:Timer = new Timer(1000,0);

		public function Dodge()
		{
			mcStartButton = new StartButton ;
			mcStartButton.x = 152;
			mcStartButton.y = 164;
			
			
			addChild(mcStartButton);
			mcStartButton.addEventListener(MouseEvent.CLICK, startGame);
			myTimer.addEventListener(TimerEvent.TIMER, differentStrides);
		        myTimer.start();
			mcBob = new Bob();
			MovieClip(mcStartButton).gotoAndStop(2);
			mcBob.x = mcBobX;
			mcBob.y = mcBobY;
			

		}
		//start game
		public function startGame(event:MouseEvent):void
		{
			//deleting and switching
			removeChild(mcStartButton);
			mcStartButton.removeEventListener(MouseEvent.CLICK, startGame);
			mcBob = new Bob();
			MovieClip(mcBob).gotoAndStop(2);
			mcBob.x = mcBobX;
			mcBob.y = mcBobY;
			addChild(mcBob);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
			stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
			addEventListener(Event.ENTER_FRAME, bobAnimation);
			lastTime = getTimer();
			
		    

		}
		//Animation
		private function bobAnimation(event:Event):void
		{

			var timePassed:int = getTimer() - lastTime;
			lastTime += timePassed;
			//check boundries////////////
			////////////////////////////////////
			if (leftArrow == true)
			{

				if (mcBob.x < 18)
				{
					leftArrow = false;
					mcBob.x = 23;
				}
			}
			if (rightArrow == true)
			{
				if (mcBob.x > 530)
				{
					rightArrow = false;
					mcBob.x = 530;

				}
			}
			if (upArrow == true)
			{
				if (mcBob.y < 15)
				{
					upArrow = false;
					mcBob.y = 13;
				}
			}
			if (bottomArrow == true)
			{
				if (mcBob.y > 381)
				{
					bottomArrow = false;
					mcBob.y = 381;
				}
			}

			///move object
			if (leftArrow == true)
			{
				mcBobX += (mcBobDX*timePassed/1000)*-1;

			}
			if (rightArrow == true)
			{
				mcBobX += (mcBobDX*timePassed/1000);

			}

			if (upArrow == true)
			{
				mcBobY += (mcBobDX*timePassed/1000)*-1;

			}
			if (bottomArrow == true)
			{
				mcBobY += (mcBobDX*timePassed/1000);

			}

			mcBob.x = mcBobX;
			mcBob.y = mcBobY;

			/////rotate char
			if (upArrow == true)
			{
				mcBob.rotation = 0;
			}
			if (bottomArrow == true)
			{
				mcBob.rotation = 180;
			}

			if (leftArrow == true)
			{
				if (upArrow == true)
				{
					mcBob.rotation = 315;
				}
				else if (bottomArrow == true)
				{
					mcBob.rotation = 225;
				}
				else
				{
					mcBob.rotation = 270;
				}
			}
			if (rightArrow == true)
			{
				if (upArrow == true)
				{
					mcBob.rotation = 45;
				}
				else if (bottomArrow == true)
				{
					mcBob.rotation = 135;
				}
				else
				{
					mcBob.rotation = 90;
				}
			}

		}

	

	function differentStrides(e:TimerEvent):void
	{
		if (leftArrow == true || rightArrow == true || upArrow == true || bottomArrow == true)
		{

			makeStride++;

			if (makeStride == 3)
			{
			makeStride = 1;
			}

			MovieClip(mcBob).gotoAndStop(makeStride);
			trace(makeStride);
		}
	}

		function keyDown(event:KeyboardEvent):void
		{
			if (event.keyCode == 37)
			{
				leftArrow = true;

			}
			else if (event.keyCode == 39)
			{
				rightArrow = true;

			}
			else if (event.keyCode == 38)
			{
				upArrow = true;

			}
			else if (event.keyCode == 40)
			{
				bottomArrow = true;

			}
		}

		function keyUp(event:KeyboardEvent):void
		{
			if (event.keyCode == 37)
			{
				leftArrow = false;

			}
			else if (event.keyCode == 39)
			{
				rightArrow = false;
			}
			else if (event.keyCode == 38)
			{
				upArrow = false;
			}
			else if (event.keyCode == 40)
			{
				bottomArrow = false;
			}
		}

	}

}

```

I put this into the constructor function and when the program adds the child its frame doesn’t come out to what I want it to.

```auto
MovieClip(mcStartButton).gotoAndStop(2);

```

Thanks.
