I'm trying to add the QuickKong class to a game I'm making, as described here: http://www.kongregate.com/forums/90-kongregate-apis/topics/199155-quickkong-easy-kong-api-integration
To call the class, you use:
QuickKong.connectToKong(stage);
However, it keeps giving me:
error 1120: Access of undefined property stage.
Any suggestions? Thanks!
The stage is a property of a
DisplayObject
. When aDisplayObject
is not on theStage
its stage property isundefined
.So, you need to make sure the stage is available when you run
QuickKong.connectToKong(stage);
.If you do this in the constructor of your document class it should work just fine. Chances are you're trying to do this in some other class that doesn't have a stage property.
If the class you're trying to run this in extends a
DisplayObject
such asMovieClip
orSprite
you can listen for when it is added to the stage and then run yourQuickKong
code. Like this:}
Now, if for some reason you are not running your
QuickKong
code in a class that has access to the stage you should pass a reference to the stage into that class's constructor, like this:Lastly, in your document class you could make a static variable reference the stage. Like this:
}
Now, you can just say:
Main.stage
anywhere in your code when you need to talk about the stage: