Help with movement

Hello! I’m a new guy here at kirupa forum and i must say it’s really nice! :slight_smile:

Started actionscript 2 days ago and i need a little help with this code.

Obviously i dont get any movement :confused: anybody knows why?


var right:Boolean = false;
var left:Boolean = false;
var up:Boolean = false;
var down:Boolean = false;

var xspeed:Number = 1;
var yspeed:Number = 1;

stage.addEventListener(Event.ENTER_FRAME, movement);
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeys);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUps);

function checkKeys(event:KeyboardEvent)
{
    if(event.keyCode == 39)
    {
        trace("Right key is down");
        right = true;
    }
    
    if(event.keyCode == 37)
    {
        trace("Left key is down");
        left = true;
    }
    
    if(event.keyCode == 38)
    {
        trace("Up key is working");
        up = true;
    }
    
    if(event.keyCode == 40)
    {
        trace("Down key is working");
        down = true;
    }
}

function keyUps(event:KeyboardEvent)
{
    if(event.keyCode == 39)
    {
        event.keyCode = 0;
        right = false;
        trace("Right key released");
    }
    
    if(event.keyCode == 37)
    {
        event.keyCode = 0;
        left = false;
        trace("Left key released");
    }
    
    if(event.keyCode == 38)
    {
        event.keyCode = 0;
        up = false;
        trace("Up key released");
    }
    
    if(event.keyCode == 40)
    {
        event.keyCode = 0;
        down = false;
        trace("Down key released");
    }
    
}

function movement(Event)
{
    if(right = true)
    {
        this.x += xspeed;
    }
    
    if(left = true)
    {
        this.x -= xspeed;
    }
    
    if(up = true)
    {
        this.y -= xspeed;
    }
    
    if(down = true)
    {
        this.y += xspeed;
    }
}