Trying to get the space bar to do an action in ActionScript.
Here is bits of the code that are relative.
var space:Boolean = false;
.
stage.addEventListener(KeyboardEvent.SPACE, kSpace);
.
function kSpace(e:KeyboardEvent)
{
if (e.keyCode == 40)
{
down = false;
}
if (e.keyCode == 38)
{
up = false;
}
if (e.keyCode == 32)
{
shoot = true;
}
}
function shootBullet()
{
var bullet1:bullet = new bullet();
bullet1.x = ship.x + ship.height / 2;
bullet1.y = ship.y;
bulletContainer.addChild(bullet1);
}
Getting the error Scene 1, Layer ‘Actions’, Frame 2, Line 17 1119: Access of possibly undefined property SPACE through a reference with static type Class.
Line 17 being stage.addEventListener(KeyboardEvent.SPACE, kSpace);
Would love to get this sorted 🙂
KeyboardEvent.SPACEis not an event. Try listening to eitherKeyboardEvent.KEY_DOWNorKeyboardEvent.KEY_UP