1120:访问未定义的属性k

时间:2014-10-12 06:33:43

标签: actionscript-3 flash

显然,我的代码不允许我为我的交互式东西制作一个39(左箭头键),因为我的作业需要帮助。作为一名大学生,这是我的新语言,Adobe Actionscript 3.0就是这里使用的语言。

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
        }



    }

    }


    }

1 个答案:

答案 0 :(得分:2)

问题很简单,k在代码中的任何位置都不存在,n会这样做。

解决问题的一种方法是替换

public function keyPressed(n:KeyboardEvent)

public function keyPressed(k:KeyboardEvent)