PDA

View Full Version : addChild() from _NOT_ document class



Jao
November 6th, 2007, 05:22 PM
Hello everyone,

Recently started educating myself with AS3. And, of course, came to a dead end: I've found that addChild adds a sprite to the Stage when it's called from Document Class. But what if i have my custom class, that i'm Importing to a stage with "import com.blabla.bla.x"; Then of course, I fire up my class and even passing a var to it for processing :

var l = (root.loaderInfo.parameters.lang == undefined) ? 'ee' : root.loaderInfo.parameters.lang;
var mm:x= new x(l);

all works ok, all traces out. But, can't addChild from my .as file to the stage. Anyone knows where to dig?

Thanks,
All the best.

senocular
November 6th, 2007, 05:52 PM
If the class itself is not a display object added to the display list (at which point it would just add the new instance to iteself) then a reference to the stage would need to be passed to that instance if you wanted to add an instance to it from that instance. Either that or you need a way to be able to access stage from a global source like a TopLevel class.

Jao
November 6th, 2007, 06:55 PM
Thank you for you reply.

All looks understandable, but i don't have enough technical skills to fix code. My class is as follows:


package ee.adpro.hindreku.menu
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.*;
import flash.errors.*;
import flash.xml.*;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.display.Stage;

public class MMenu extends Sprite
{
private var loader:URLLoader = new URLLoader();
private var request:URLRequest = new URLRequest("menu.xml");
private var mainXML:XML;
private var currentLaguage:String;
private var eventSprite:Sprite;

public function MMenu(l:String) {
currentLaguage = l;
getMenuItems();
};

...

private function buildMenu(buttons:XMLList){
//trace(buttons);

eventSprite = new Sprite();
addChild(eventSprite);
eventSprite.graphics.beginFill(0xff0000);
eventSprite.graphics.drawCircle(0, 0, 100);
eventSprite.graphics.endFill();

};

}
}


At this point i understood, that Sprite, MovieClip extend to DisplayObject class. But, still, no solution in my mind yet.