I’m having trouble getting this part of Sen’s code to function! I attached his tutorial fla! I’ve searched in the AS help in Flash and tried modifying the Key.addlistener object but it still won’t respond to the arrow keys!
Sen’s code
// set the ball to recognize key presses and move based on them
Key.addListener(ball);
ball.onKeyDown = function(){
var xmove, ymove;
if (Key.isDown(Key.UP)){
ymove = 1;
}else if (Key.isDown(Key.DOWN)){
ymove = -1;
}else if (Key.isDown(Key.LEFT)){
xmove = -1;
}else if (Key.isDown(Key.RIGHT)){
xmove = 1;
}
// update new position based on ball's current
xmove += this.x;
ymove += this.y;
if (IsValidTile(xmove, ymove)){
moveToGridSpace(xmove, ymove);
}
}
My attempt
// set the ball to recognize key presses and move based on them
ball = new Object ();
ball.onKeyDown = function(){
var xmove, ymove;
if (Key.isDown(Key.UP)){
ymove = 1;
}else if (Key.isDown(Key.DOWN)){
ymove = -1;
}else if (Key.isDown(Key.LEFT)){
xmove = -1;
}else if (Key.isDown(Key.RIGHT)){
xmove = 1;
}
Key.addListener(ball);
// update new position based on ball's current
xmove += this.x;
ymove += this.y;
if (IsValidTile(xmove, ymove)){
moveToGridSpace(xmove, ymove);
}
}
What is wrong?