Question

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.

Was it helpful?

Solution 2

Assuming Main is your document class, you could do this a few different ways.

  1. As mentioned in another answer, make your variable public. Then access it like so:

    Main(root).MazeNr1
    
  2. 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
    

OTHER TIPS

Make the variable 'public':

public var MazeNr1:Level = new Level();

Then you can access it from outside the class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top