I’m currently trying to add a ‘border’ to my code so the player object doesn’t move off screen when one of the arrow keys is held. I’m pretty new to ActionScript hence my lack of knowledge, so any help given will be greatly appreciated.
I’m unsure if my current coding is needed to help with this so I’ll paste it in case.
import flash.events.Event;
var bg:background = new background
addChild (bg);
var pp: PlayerPic = new PlayerPic
addChild (pp);
pp.x= 125
pp.y= 550
pp.height = 40
pp.width = 50
stage.addEventListener(KeyboardEvent.KEY_DOWN, arrowMove)
function arrowMove(event:KeyboardEvent):
void
{
if (event.keyCode == Keyboard.LEFT){pp.x = pp.x - 5};
if (event.keyCode == Keyboard.RIGHT){pp.x = pp.x + 5};
if (event.keyCode == Keyboard.UP){pp.y = pp.y - 5};
if (event.keyCode == Keyboard.DOWN){pp.y = pp.y + 5};
};