# How to "flip" 2d character when moving

**URL:** <https://forum.kirupa.com/t/how-to-flip-2d-character-when-moving/320157>\
**Category:** flash\
**Created:** [March 15, 2011, 2:55pm UTC](https://forum.kirupa.com/t/how-to-flip-2d-character-when-moving/320157 "2011-03-15T14:55:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![R\_T\_WALLER](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@R\_T\_WALLER](https://forum.kirupa.com/u/R_T_WALLER)\
**Post date:** [March 15, 2011, 2:55pm UTC](https://forum.kirupa.com/t/how-to-flip-2d-character-when-moving/320157/1 "2011-03-15T14:55:31Z")

</div>

I am brand new to AS so I do not know very much yet.

I have a mc called boy and I have an instance of that mc called boy\_mc. I have figured out how to make his position change on the stage, but I cannot figure out how to do some other things. Here is the code that I have so far:

```auto
import flash.events.KeyboardEvent;

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);

function keyPressed(evt:KeyboardEvent):void
{
	switch(evt.keyCode)
	{
		case Keyboard.RIGHT :
		boy_mc.x += 5;
		break;
		case Keyboard.LEFT :
		boy_mc.x -= 5;
		break;
		default :
		break;
	}
	
	switch(evt.keyCode)
	{
		case Keyboard.UP :
		boy_mc.y -= 5;
		break;
		case Keyboard.DOWN :
		boy_mc.y += 5;
		break;
		default :
		break;
	}
}

```

I am trying to learn 3 things.

1. How do I make him be facing left when I push left and facing right when I push to right?

2. How to I restrict him to a certain area of the stage? I am going to have some buildings on the top and I don’t want him to be able to walk past the street level. So basically I don’t want him to be able to go off the stage or up some to be determined height.

3. When he walks up and touches a door on my stage, I want to jump to another place in the timeline. I do not know how to do that though, but I assume it has something to do with collision detection?

Thanks in advance!
