AS3 - Event.ENTER_FRAME - error 1119

守給你的承諾、 提交于 2020-01-17 06:43:37

问题


I'm trying to develop a simple game in Adobe Animate and AS3.

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);

It throws an error saying:

 Can´t access probably undefined property ENTER_FRAME referenced with static type Class

i did this before, but i don't touch as3 for a couple of years, can you tell me whats going wrong here?

Thanks in advance and happy programming!


回答1:


You can extends your class with:

public class GameCore extennds EventDispatcher 

and use this code

this.addEventListerner(Event.EnterFrame,gameloop)

maybe it works



来源:https://stackoverflow.com/questions/44304338/as3-event-enter-frame-error-1119

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!