mercredi 24 février 2016

How can I call timeline-specific methods from an external file in AS3?

I'm creating a game is Flash CS5 with ActionScript 3. To simplify things, I've created a file (Game.as) in the top layer of my source folder. My Game.as file looks as follows:

package {
    public class Game {
        public static function fail():void {
            stop();

            var restart:RestartButton = new RestartButton();
            addChild(restart);

            restart.x = stage.stageWidth/2;
            restart.y = stage.stageHeight/2;

            Game.createButton(restart, function(e:MouseEvent):void { gotoAndPlay (1, "Title Sequence") });
        }
    }
}

I would supposedly call Game.fail () from a frame on a timeline a scene, but I get these compiler errors:

Line 11 1180: Call to a possibly undefined method stop. Line 19 1180: Call to a possibly undefined method gotoAndPlay. Line 17 1120: Access of undefined property stage. Line 16 1120: Access of undefined property stage. Line 14 1180: Call to a possibly undefined method addChild.

Why are these errors happening? What can I do to fix them?

Thanks for your help in advance.

Aucun commentaire:

Enregistrer un commentaire