I have a game engine class that creates my main character instance and game border instance when the game is loaded like so:
public class Engine extends MovieClip
{
var char:Char = new Char(stage);
stage.addChildAt(char, 1);
var border1:Border = new Border();
stage.addChild(border1);
}
I would like to access the variable border1 that was created in the Engine class inside of my Char class. Is this possible, and if so, how would I do it?
I’ve tried changing the code so border1 is static like so
static var border1:Border = new Border();
But then I get
error 1012: The static attribute may be used only on definitions inside a class.
You could do this a few ways.
You could also do this without passing the border1 instance to the constuctor, and instead just add a method that sets this property.
Another option would be to make the Engine instance maintain a reference to the border and allow communication through the Engine instance. For example,
Now, if the char instance has a reference to the engine instance, then the border instance can be referenced by
myEngineInstance.border1.Or you can make the border instance static. Making it static would allow for code inside of the Char instance like: