因此,我收到了一条错误1180消息,其中包含以下代码:
package objects.moving.dudes {
import flash.utils.Timer;
import objects.moving.Moving;
import misc.MoveTimer;
public class Dude extends Moving {
public function Dude() {
addEventListener(Event.ADDED_TO_STAGE, stageAddHandler);
}
public var theMoveTimer;
public function stageAddHandler(e:Event) {
addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
removeEventListener(Event.ADDED_TO_STAGE, stageAddHandler);
}
public function keyPressed(e:KeyboardEvent) {
theMoveTimer = new MoveTimer(e.keyCode);
}
}
}
它说,“调用一个可能未定义的方法MoveTimer”。
这是MoveTimer类:
package misc {
import flash.utils.Timer;
class MoveTimer {
private const TIMER_LENGTH = 500;
public function MoveTimer(myKeyCode:int) {
keyCode = myKeyCode;
}
public var keyCode:int;
public var timer = new Timer(TIMER_LENGTH);
}
}
我已经查看了错误1180的几种不同的可能解决方案,并且没有一种适用于此工作。有谁知道我为什么会收到这个错误?
编辑:我将代码转移到stackoverflow时犯了一些错误,我做了一些修改,使它看起来更像我的实际代码。答案 0 :(得分:1)
因为我发现您忘记将变量theMoveTimer
键入为MoveTimer
而MoveTimer
类未导入Dude
类。
尝试将theMoveTimer
的声明更改为:
public var theMoveTimer:MoveTimer;
并将以下行添加到您的导入中:
import misc.MoveTimer;
答案 1 :(得分:0)
我认为你的Dude课程的第一行应该以'package'开头。那,以及Binou建议的更改,即:将MoveTimer类型添加到您的theMoveTimer声明并在Dude类中导入MoveTimer类。
答案 2 :(得分:0)
解决方案!我觉得很愚蠢,但我需要在public
课程中添加MoveTimer
这个词:
package misc {
import flash.utils.Timer;
public class MoveTimer { //This is the line where I added the word 'public'. See my question for the incorrect version of this line.
private const TIMER_LENGTH = 500;
public function MoveTimer(myKeyCode:int) {
keyCode = myKeyCode;
}
public var keyCode:int;
public var timer = new Timer(TIMER_LENGTH);
}
}