0

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!

1
  • Did you try using 'gameLoop' instead of 'this.gameLoop'? also, gameLoop should be private unless you plan on having something else call that method. Commented Feb 19, 2012 at 15:47

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Knew it would be something like that :) Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.