瞬间,我在巫婆中遇到了一个错误,这给了我两个错误。
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.
我正在尝试使用键盘键来移动好人。
我将所有
Mouse
更改为Keyboard
。我仔细检查了所有内容,以确保没有鼠标。这是我的代码:
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);
}
}
}
}
最佳答案
您只是将这两个短语放在其中,但从未指定它们是什么。
该错误基本上意味着:
WTF is PressSPACEKey???
addEventListener是一个函数,该函数将另一个 FUNCTION 作为第二个参数。因此,不管
PressSPACEKey
是什么,它都应该是一个函数。但是,您再也没有在任何地方声明它。与此完全无关的是,您的代码中有两个功能,分别为
pressed
和unpressed
。我不确定为什么要添加最后一句话,也不确定为什么我帖子中的某些单词是粗体和大写的。不知道,真的...
关于actionscript-3 - 我的错误在哪里? (Flash CS6 AS3错误: 1120),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28220989/