If you want to reference the Stage from your multyLoader
instance, then it needs to be on the display list first. The safest way to do that is to listen for the ADDED_TO_STAGE
event and only reference the stage after that event has fired.
public function My_Loader(loading_holder, myLoaderURL:String){
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
protected function onAddedToStage(e:Event){
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
loading_holder.x = (stage.stageWidth - loading_holder.width) / 2;
// etc...
}
You could also just make sure to only call the My_Loader
function after you are sure theLoader
has been added to the display list. It's not always as straightforward as it seems though.
A third option, if you don't want theLoader
to be on the display list for whatever reason, would be to pass theLoader
a reference to the stage from the parent class. You could add it as an argument to your My_Loader
function.
public function My_Loader(loading_holder, myLoaderURL:String, myStage:Stage){
loading_holder.x = (myStage.stageWidth - loading_holder.width) / 2;
// etc...
}
calling it from the parent class like this:
theLoader.My_Loader(mc_loaderHolder, myXML.IMAGE[1].@URL, this.stage);