# This should be simple...but it doesn't work

**URL:** https://forum.kirupa.com/t/this-should-be-simple-but-it-doesnt-work/322580
**Category:** Uncategorized
**Created:** [May 26, 2011, 2:23am UTC](https://forum.kirupa.com/t/this-should-be-simple-but-it-doesnt-work/322580 "2011-05-26T02:23:42Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Blargh](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Blargh](https://forum.kirupa.com/u/Blargh)
#### Post date: [May 26, 2011, 2:23am UTC](https://forum.kirupa.com/t/this-should-be-simple-but-it-doesnt-work/322580/1 "2011-05-26T02:23:42Z")

</div>

I made a simple little program to move a movieclip around, but it doesn’t work, and for the life of me I can’t seem to figure out why. It’s so simple! The program runs with no errors but the movieclip won’t move. I put in a trace statement that doesn’t return anything, so it’s gotta be something the matter with my event listener.

```auto
package {
    
    import flash.display.MovieClip;
    import flash.display.Stage;
 
    //our Engine class it extends MovieClip
    public class Engine extends MovieClip
    {
        //our constructor function. This runs when an object of 
        //the class is created
        public function Engine() 
        {
            //create an object of our ship from the Ship class
            var ourShip:Ship = new Ship();
            //add it to the display list
            stage.addChild(ourShip);
 
            ourShip.x = stage.stageWidth / 2;
            ourShip.y = stage.stageHeight / 2;
        }
 
    }
 
}

```

```auto
package 
{

    import flash.display.MovieClip;
    import flash.ui.Keyboard;
    import flash.events.*;

    public class Ship extends MovieClip
    {

        
        public function Ship()
        {
            addEventListener(KeyboardEvent.KEY_DOWN, loop);
        }

        private function loop(event:KeyboardEvent):void
        {
            if (event.keyCode == Keyboard.LEFT)
            {
                this.x -= 2;
            }
            else if (event.keyCode == Keyboard.RIGHT)
            {
                this.x += 2;
            }
            else if (event.keyCode == Keyboard.UP)
            {
                this.y -= 2;
            }
            else if (event.keyCode == Keyboard.DOWN)
            {
                this.y += 2;
            }
        trace (event.keyCode);
        }

    }

}

```
