The Idiot Gamer
The Idiot Gamer

Reputation: 103

Where is my error? (Flash CS6 AS3 error: 1120)

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);
                }
         }
    }
}

Upvotes: 0

Views: 192

Answers (2)

Alexander Steshenko
Alexander Steshenko

Reputation: 11

In error clearly says that the properties are incorrect.

var KeyboardIsDown = false; var velocity = 0 var score = 0; stage.addEventListener(KeyboardEvent.KEY_DOWN, pressed); stage.addEventListener(KeyboardEvent.KEY_UP, unpressed); 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); } } } }

Upvotes: 1

null
null

Reputation: 5255

You just put these two phrases in there but you never specify what they are.

The error basically means:

WTF is PressSPACEKey???

addEventListener is a function that takes a another FUNCTION as a second argument. So whatever PressSPACEKey is, it should be a function. But again, you never declared it anywhere.

Entirely unrelated to that, you have two FUNCTIONS in your code named pressed and unpressed.

I'm not sure why I added this last sentence and am also in doubt why certain words in my post are bold and in caps. No idea, really...

Upvotes: 1

Related Questions