# Converting NG Movement Tutorial into a Class

**URL:** <https://forum.kirupa.com/t/converting-ng-movement-tutorial-into-a-class/281601>\
**Category:** programming\
**Created:** [February 11, 2009, 3:56am UTC](https://forum.kirupa.com/t/converting-ng-movement-tutorial-into-a-class/281601 "2009-02-11T03:56:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xanderdavis](https://avatars.discourse-cdn.com/v4/letter/x/7c8e57/32.png) [@xanderdavis](https://forum.kirupa.com/u/xanderdavis)\
**Post date:** [February 11, 2009, 3:56am UTC](https://forum.kirupa.com/t/converting-ng-movement-tutorial-into-a-class/281601/1 "2009-02-11T03:56:59Z")

</div>

I’m trying to move this:

> **[AS3: Movement with Keys](https://www.newgrounds.com/bbs/topic/700462)**
>
> AS3: Main Aha, my first AS3 tutorial! Let's begin! Here's what you will be learning how to do using AS3:Example After struggling to find a way to make object movement using AS3 without the use of deltas code (which I refused to use =p) I finally f...

…into its own class. That way, control code can be partitioned off and can separately affect the Level, another class.

However, even though the FLA compiles all code without error, any keyboard input fails to trigger any traces, let alone any movements. It needs to move the world (public static MovieClip property) in the Levels class. The Levels class successfully triggers GameControls(); here in the Control class, but the event listeners themselves seem inoperative.

What am I missing? Here’s what I have:

**Control.as**

```auto

package engine
{
    import flash.display.MovieClip;
    import flash.display.*;
    import flash.events.*;
    
    public class Controls extends MovieClip
    {
        public static var keyMoveLeft:Boolean = false;
        public static var keyMoveRight:Boolean = false;
        public static var keyMoveUp:Boolean = false;
        public static var keyMoveDown:Boolean = false;
        public static var keyRun:Boolean = false;
        public static var speed = 20;
        
        public function Controls():void
        {
            trace("Controls Engaged");
        }
        
        public function checkKeys(event:KeyboardEvent):void
        {

            if (event.keyCode == 65) {
                trace("Player is moving left");
                keyMoveLeft = true;
            }
            if (event.keyCode == 68) {
                trace("Player is moving right");
                keyMoveRight = true;
            }
            if (event.keyCode == 87) {
                trace("Player is moving up");
                keyMoveUp = true;
            }
            if (event.keyCode == 83) {
                trace("Player is moving down");
                keyMoveDown = true;
            }
            if (event.keyCode == 16) {
                trace("Player is running");
                keyRun = true;
            }
        }
        
        public function keyUps(event:KeyboardEvent):void
        {
            if (event.keyCode == 65) {
                event.keyCode = 0;
                keyMoveLeft = false;
                trace("Player stopped moving left");
            }
            if (event.keyCode == 68) {
                event.keyCode = 0;
                keyMoveRight = false;
                trace("Player stopped moving right");
            }
            if (event.keyCode == 87) {
                event.keyCode = 0;
                keyMoveUp = false;
                trace("Player stopped moving up");
            }
            if (event.keyCode == 83) {
                event.keyCode = 0;
                keyMoveDown = false;
                trace("Player stopped moving down");
            }
            if (event.keyCode == 16) {
                event.keyCode = 0;
                keyRun = false;
                trace("Player stopped running");
            }
        }
        
        public function movement(event:Event):void
        {
            if (keyMoveLeft == true)
            {
                Levels.world.x += speed;
            }
            if (keyMoveRight == true)
            {
                Levels.world.x -= speed;
            }
            if (keyMoveUp == true)
            {
                Levels.world.y += speed;
            }
            if (keyMoveDown == true)
            {
                Levels.world.y -= speed;
            }
            if (keyRun == true)
            {
                speed = 20;
            }
            if (keyRun == false)
            {
                speed = 10;
            }
        }
        
        public function GameControls():void
        {
            addEventListener(Event.ENTER_FRAME, movement);
            addEventListener(KeyboardEvent.KEY_DOWN , checkKeys);
            addEventListener(KeyboardEvent.KEY_UP, keyUps);
        }
        
    } // End Class
} //End Package */

```
