简体   繁体   中英

ActionScript game loop not running

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM