I don't think you want to have your Shared
class inherit from your Main
class, remember that by using the extends Main
after your class, you inherit all the code from it, which means you're inheriting the function that creates an instance of your Shared
class, which may cause a stack overflow.
Extending a class is not the same as getting an instance of your class. All the i/j/size etc properties of the main class are a completely separate instance than the ones that will be in your Shared class that inherits Main.
Here is probably what you want to do:
public class Shared extends Sprite { //extend Sprite instead of Main
public var m:Mirror; //don't instantiate these objects yet, just declare them
public var g:Grid;
public var b:Ball;
public var mc:MovieClips;
public var l:Level;
public function Shared(main:Main){ //pass in a reference to your main class instance
//instanciate these objects in your constructor
m = new Mirror(main.span, main.i*main.span+main.j, main._x, main._y, main.size, main.d); //all these vars (span, i,j,_x,_y, size, d, addl) are not defined anywhere that you've shown, I'm assuming they are part of your main class
g = new Grid(main.i*main.span+main.j,main.size, main.addl, main.span, main._x, main._y);
b = new Ball(30);
mc = new MovieClips(30, main._x, main._y, main.size, main.span);
l = new Level(main.levelCount);
this.addChild(m);
this.addChild(g);
this.addChild(b);
this.addChild(mc);
this.addChild(l);
}
}
In your main class:
private function init(e:Event = null):void
{
var sh:Shared = new Shared(this); //pass a reference to this Main class instance
//stage.addChild(sh.b); // just add the Shared instance to the stage directly
//stage.addChild(sh.mc);
//stage.addChild(sh.l);
addChild(sh); //you only need to add the Shared class instance, since you've already added those other objects in the Shared class
/* no idea what your trying to do here, but I don't think it's what you're expecting
for (i = 0; i < span; i++)
{
for (j = 0; j < span; j++)
{
stage.addChild(sh.g);
if(addl.indexOf(i*span+j)==true){
stage.addChild(sh.m);
}
}
}
*/
}
Please explain your code a bit more and I can update this answer to be more relevant.