In flash, I am getting an error in witch it giving me two errors.
Scene 1, Layer 'good guy', Frame 1, Line 4 1120: Access of undefined property PressSPACEKey.
Scene 1, Layer 'good guy', Frame 1, Line 4 1120: Access of undefined property ReleaseSPACEKey.
I am trying to use keyboard keys to move the good guy.
I changed all Mouse
to Keyboard
. I looked through it all to make sure there are no Mouse.
Here is my code:
var KeyboardIsDown = false;
var velocity = 0
var score = 0;
stage.addEventListener(KeyboardEvent.KEY_DOWN, PressSPACEKey);;
stage.addEventListener(KeyboardEvent.KEY_UP, ReleaseSPACEKey);
function pressed (n:KeyboardEvent)
{
KeyboardIsDown = true;
}
function unpressed (n:KeyboardEvent)
{
KeyboardIsDown = false;
}
addEventListener(Event.ENTER_FRAME, mainLoop);
function mainLoop (e:Event)
{
output.text = "Score: " + score;
score += 1
if (KeyboardIsDown)
{
if (velocity < -10)
{
velocity = -10;
}
gg_mc.y -= velocity
}
else
{
gg_mc.y += velocity;
}
velocity += 0.03
; //yes, this is on a new line
for (var I = 0; I < numChildren; I++)
{
if (getChildAt(I) is bad || getChildAt(I) is B)
{
var b = getChildAt(I) as MovieClip;
if (b.hitTestObject(gg_mc))
{
var explosion = new boom ();
explosion.x = gg_mc.x;
explosion.y = gg_mc.y;
addChild(explosion);
}
}
}
}