没有键盘输入AS3

时间:2014-04-10 23:56:14

标签: actionscript-3 flash keyboard-input

所以我试图从用户那里获得键盘输入来移动角色。它适用于我正在使用的另一个程序,我复制粘贴,但它不适用于此。它给了我Line 87, Column 38 1119: Access of possibly undefined property EVENT_FRAME through a reference with static type Class.我似乎无法弄清楚问题是什么。

这是我点击开始按钮时使用的buttonClick功能。

    public function buttonClick(ev:MouseEvent):void
    {
        createGameScreen();
        this.mcLink.gotoAndPlay("Idle");
        this.mcLink.x=50;
        this.mcLink.y=200;
        this.mcLink.scaleX=this.mcLink.scaleY=3;
        this.stage.addEventListener(Event.EVENT_FRAME, this.enterFrameHandler, false, 0, true);
    }

这是键盘输入的事件处理函数。

public function enterFrameHandler($e:Event):void
    {
        if (this.mcLink)
        {               
            if (KeyboardManager.instance.isKeyDown(KeyCode.DOWN))
            {
                if (this.mcLink.y + this.mcLink.height > this.stage.stageHeight || this.mcLink.y - this.mcLink.height <= 0)
                {
                    this.mcLink.y += -15;
                    mcLink.gotoAndPlay("Idle");
                    return;
                }
                this.mcLink.y += _nHeroMovementSpeed;
                mcLink.gotoAndPlay("Down");
            }
            else if (KeyboardManager.instance.isKeyDown(KeyCode.UP))
            {
                if (this.mcLink.y + this.mcLink.height > this.stage.stageHeight || this.mcLink.y - this.mcLink.height <= 0)
                {
                    this.mcLink.y += 15;
                    mcLink.gotoAndPlay("Idle");
                    return;
                }
                this.mcLink.y -= _nHeroMovementSpeed;
                mcLink.gotoAndPlay("Up");
            }

            if (KeyboardManager.instance.isKeyDown(KeyCode.LEFT))
            {
                if (this.mcLink.x + this.mcLink.width > this.stage.stageWidth || this.mcLink.x - this.mcLink.width <= 0) 
                {
                    this.mcLink.x += 15;
                    mcLink.gotoAndPlay("Idle");
                    return;
                }                   
                this.mcLink.x -= _nHeroMovementSpeed;
                mcLink.gotoAndPlay("Left");

            }
            else if (KeyboardManager.instance.isKeyDown(KeyCode.RIGHT))
            {   
                if (this.mcLink.x + this.mcLink.width > this.stage.stageWidth || this.mcLink.x - this.mcLink.width <= 0) 
                {
                    this.mcLink.x += -15;
                    mcLink.gotoAndPlay("Idle");
                    return;
                }
                this.mcLink.x += _nHeroMovementSpeed;
                mcLink.gotoAndPlay("Right");
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

您的意思是Event.ENTER_FRAME吗?

this.stage.addEventListener(Event.ENTER_FRAME, this.enterFrameHandler, false, 0, true);
//                                ^^^^^^^^^^^ EVENT_FRAME isn't a known Event.