Reputation: 836
So I'm trying to get keyboard input from the user to move a character. It works in another program that I was using, and I copy pasted, but it isn't working in this one. It gives me Line 87, Column 38 1119: Access of possibly undefined property EVENT_FRAME through a reference with static type Class.
I can't seem to figure out what the issue is.
This is the buttonClick function that is used to when I hit the start button.
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);
}
This is the event handler function for the keyboard input.
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");
}
}
}
Upvotes: 0
Views: 53
Reputation: 39456
Did you mean Event.ENTER_FRAME
?
this.stage.addEventListener(Event.ENTER_FRAME, this.enterFrameHandler, false, 0, true);
// ^^^^^^^^^^^ EVENT_FRAME isn't a known Event.
Upvotes: 1