问题描述
我正在尝试使用Adobe Animate和AS3开发一个简单的游戏.
I'm trying to develop a simple game in Adobe Animate and AS3.
我有一个类GameCore
,我想在其中添加ENTER_FRAME事件侦听器.
I have a class GameCore
where I want to add an ENTER_FRAME event listener.
package as3 {
import flash.display.Stage;
import flash.display.MovieClip;
import flash.events.*;
import as3.movieclips.RocketShip;
public class GameCore {
var rocket:RocketShip;
var stage:Stage;
var timeline:MovieClip;
var i:int;
public function GameCore( stage:Stage ) {
// constructor code
this.rocket = new RocketShip();
this.stage = stage;
this.timeline = this.stage as MovieClip;
this.i = 0;
this.stage.addEventListener(Event.ENTER_FRAME, gameLoop);
}
public function goToMainScreen():void {
this.timeline.goToAndStop("MainScreen");
}
public function goToGameScreen():void {
this.timeline.goToAndStop("GameScreen");
}
public function startGameLoop():void {
}
public function gameLoop(event:Event){
trace(this.i);
this.i += 1;
}
}
}
当我尝试在时间轴框架上执行代码时,如下所示:
When I try to execute the code on a timeline frame like so:
import as3.GameCore;
var game:GameCore = new GameCore(stage);
它抛出一个错误,说:
Can´t access probably undefined property ENTER_FRAME referenced with static type Class
我以前是这样做的,但是我几年都没碰过as3了,你能告诉我这里出了什么问题吗?
i did this before, but i don't touch as3 for a couple of years, can you tell me whats going wrong here?
感谢您提前编程!
推荐答案
好的,所以这可能是一个长镜头,但我认为您不必在其中包含(stage).您可以设置game.x和game.y以及其他一些变量,然后设置stage.addchild(game).如果您想要多个这种类型的对象,有时创建一个数组会有所帮助,但是您还需要做其他语义上的工作.
Ok so this might be a long shot but I don't think you have to have the (stage) in there. You can set game.x and game.y, and a few other variables, and then stage.addchild(game). if you want multiple objects of that type it is sometimes helpful to make an array, but there are other semantic stuff you have to do to make that work.
我知道这是一篇过时的文章,但希望能对某人有所帮助.
I know this is an old post but hopefully, it helps someone.
这篇关于AS3-Event.ENTER_FRAME-错误1119的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!