AdilStudent
AdilStudent

Reputation: 1

1120: Access of undefined property k

Apparently, my code doesn't let me make a 39 (left arrow key) to my interactive thing for my assignment need help. As a college student, this is me being a new language, Adobe Actionscript 3.0 is the language used here.

package  {

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;


public class Main extends MovieClip
{
    //Global variables, as in it's beyond the local as in the entire coding not one part
    var idiot


    public function Main() {
        // constructor code

        idiot = new RedCircle
        addChild(idiot);
        idiot.x = Math.random()* (stage.stage.width)
        idiot.y = Math.random()* (stage.stage.height)

        if (idiot.x > stage.stageWidth/2 && idiot.y < stage.stageHeight/2)
        { 
            trace ("aaaahhhhh")
            idiot.rotation = 135
        }

        //Interactive side
        idiot.addEventListener(MouseEvent.CLICK, shootsnot);
        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);

    }// Main()

    public function shootsnot (n:MouseEvent)

    {
        //shoot snot
        trace ("NEVER ENDING DAKKA");

        var snotty = new Snot();
        addChild(snotty)
        snotty.x = idiot.x
        snotty.y = idiot.y + idiot.height/2;

    }

    public function keyPressed (n:KeyboardEvent)

    {
        //pressing something
        trace ("Key Pressed")

        trace(k.keyCode);

        if (k.keyCode == 37)

        {   
            //left press
            idiot.x = idiot.x - 10
        }



    }

    }


    }

Upvotes: 0

Views: 48

Answers (1)

user2655904
user2655904

Reputation:

The problem is simple, k doesn't exist anywhere in your code, n does however.

One way to solve your problem is to replace

public function keyPressed(n:KeyboardEvent)

with

public function keyPressed(k:KeyboardEvent)

Upvotes: 2

Related Questions