0
votes

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!

2

2 Answers

0
votes

You can extends your class with:

public class GameCore extennds EventDispatcher 

and use this code

this.addEventListerner(Event.EnterFrame,gameloop)

maybe it works

0
votes

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.