# as3 game code help

**URL:** https://forum.kirupa.com/t/as3-game-code-help/332218
**Category:** flash
**Created:** [March 8, 2014, 11:00pm UTC](https://forum.kirupa.com/t/as3-game-code-help/332218 "2014-03-08T23:00:20Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![luckythelab](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@luckythelab](https://forum.kirupa.com/u/luckythelab)
#### Post date: [March 8, 2014, 11:00pm UTC](https://forum.kirupa.com/t/as3-game-code-help/332218/1 "2014-03-08T23:00:20Z")

</div>

```php
var hitObstacle:Boolean=false; // keeps track if obstacle is hitvar health=20; health_txt.text=health.toString();stage.addEventListener(KeyboardEvent.KEY_DOWN, checkkeysdown);stage.addEventListener(KeyboardEvent.KEY_UP, checkkeysup);var speed=10;var moveup=false;var movedown=false;var moveleft=false; var moveright=false;
function checkkeysdown(mykey:KeyboardEvent) { if (mykey.keyCode==Keyboard.UP) { moveup=true; } if (mykey.keyCode==Keyboard.DOWN) { movedown=true; } if (mykey.keyCode==Keyboard.LEFT) { moveleft=true; } if (mykey.keyCode==Keyboard.RIGHT) { moveright=true; }}function checkkeysup(mykey:KeyboardEvent) { if (mykey.keyCode==Keyboard.UP) { moveup=false; } if (mykey.keyCode==Keyboard.DOWN) { movedown=false; } if (mykey.keyCode==Keyboard.LEFT) { moveleft=false; } if (mykey.keyCode==Keyboard.RIGHT) { moveright=false; }
stage.addEventListener(Event.ENTER_FRAME, gameloop);function gameloop(evt:Event):void { obstacle_mc.x-=-15;{ if (obstacle_mc.x>600) obstacle_mc.x=-20; arrow_mc.x-=-10;{ if (arrow_mc.x>550) arrow_mc.x=-20; }} if (xena_mc.hitTestObject(obstacle_mc)(arrow_mc)) { if (hitObstacle==false){ //only subtract health if hitObstacle is false health--; } hitObstacle=true; health_txt.text=health.toString();   
 
 if (moveup==true) { xena_mc.y-=speed; } if (movedown==true) { xena_mc.y+=speed; } if (moveleft==true) { xena_mc.x-=speed; } if (moveright==true) { xena_mc.x+=speed; } }

```

why dosent this work??? thanks! your help is greatly appreciated
