Reputation: 35
I'm working with Flash CS6 and FlashDevelop and all the similar questions I could find deal with classes accessing stuff in other classes, but not in Main so here it is: My main initializes the level i made in Flash like so:
public class Main extends MovieClip
{
private var MazeNr1:Level = new Level();
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
addChild(MazeNr1);
}
}
And I need my instantiated level variable (MazeNr1) to be seen by other classes in my project so that I can use its parameters (like width and height which are not the same thing as stage.parameters). Thank you.
Upvotes: 0
Views: 70
Reputation: 14406
Assuming Main
is your document class, you could do this a few different ways.
As mentioned in another answer, make your variable public. Then access it like so:
Main(root).MazeNr1
Make it a static variable
public static var MazeNr1:Level;
public function Main():void
{
MaxeNr1 = new Level();
//rest of your constructor code
}
Then you can access it in any scope simply by doing this:
Main.MazeNr1
Upvotes: 0
Reputation: 3008
Make the variable 'public':
public var MazeNr1:Level = new Level();
Then you can access it from outside the class.
Upvotes: 1