ActionScript 游戏循环未运行
我正在使用 ActionScript 3 开发 Flash 游戏,并在我的文档类中包含此代码:
package com {
import flash.display.MovieClip;
import flash.display.Stage;
public class Engine extends MovieClip {
public function Engine() {
// Create a player instance
var player:Player = new Player();
addChild(player);
// Start the game loop
addEventListener(Event.ENTER_FRAME, this.gameLoop);
}
public function gameLoop(event:Event) {
trace("hello world");
}
}
}
但是,当我运行游戏时,我没有得到任何输出,而是收到此错误消息:
C:\Users\MyName\Dropbox\Uni\DAT104\flash\com\Engine.as, Line 15 1046: Type was not found or was not a compile-time constant: Event.
是否有库或我需要的东西导入以使其发挥作用?如果不明显,我想在每个新帧(文档当前设置为 30fps)上运行我的 Engine
类(文档类)的 gameLoop
方法。
谢谢!
I'm developing a Flash game using ActionScript 3 and have this code in my documents class:
package com {
import flash.display.MovieClip;
import flash.display.Stage;
public class Engine extends MovieClip {
public function Engine() {
// Create a player instance
var player:Player = new Player();
addChild(player);
// Start the game loop
addEventListener(Event.ENTER_FRAME, this.gameLoop);
}
public function gameLoop(event:Event) {
trace("hello world");
}
}
}
When I run the game, however, I don't get any output and instead get this error message:
C:\Users\MyName\Dropbox\Uni\DAT104\flash\com\Engine.as, Line 15 1046: Type was not found or was not a compile-time constant: Event.
Is there a library or something I need to import to get this to work? If it's not obvious, I want to run the gameLoop
method of my Engine
class (the documents class) on every new frame (the document is currently set to 30fps).
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Flash 可能只是在抱怨,因为它不知道在哪里可以找到 Event 类。如果您在代码中的其他导入语句之后添加
import flash.events.Event;
语句,它应该可以工作。Flash is probably just complaining because it doesn't know where to find the Event class. If you add an
import flash.events.Event;
statement after the other import statements in your code, it should work.