0

因此,我收到一条错误 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 时犯了一些错误,我进行了更改以使其看起来更像我的实际代码。

4

3 回答 3

1



as i see you forgot to type your variable theMoveTimer as MoveTimer and the MoveTimer class isn't imported in your Dude class.
Try to change your declaration for theMoveTimer to:

public var theMoveTimer:MoveTimer;

and add the following line to your imports:

import misc.MoveTimer;
于 2013-11-11T07:55:12.437 回答
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);
    }
}
于 2013-11-19T06:22:05.993 回答
0

我认为你的 Dude 类的第一行应该以“包”开头。那,以及 Binou 建议的更改,即:将 MoveTimer 类型添加到您的 theMoveTimer 声明并在您的 Dude 类中导入 MoveTimer 类。

于 2013-11-11T10:36:46.857 回答