Re-use Loader & Removing content
Posted on 01. Apr, 2009 by thornyeternity in ActionScript 3 Snippets
Standard initial load:
var myLoader:Loader = new Loader();
addChild(myLoader);
var myContent:URLRequest = new URLRequest(whichSwf);
myLoader.load(myContent);
—————————-
To get loaded content into same level:
Moves it past loader (first parent) to root (second parent).
parent.parent.addChild(containerSprite) – only works occasionally.
Rather – do not create a new loader in the movies that load something else.
//var myLoader:Loader = new Loader();
//addChild(myLoader);
var myContent:URLRequest = new URLRequest(whichSwf);
//myLoader.load(myContent);
Loader(parent).load(myContent);//it was loaded, so its parent is a loader so re-use it. Set code to NOT strict.
//Once it has loaded set the position to middle
private function completeHandler(event:Event):void {
imageContainer.getChildAt(0).x = – (imageContainer.width/2);
imageContainer.getChildAt(0).y = – (imageContainer.height/2);
}//completeHandler
————————————-
Remove all children in existing “level”:
Remove children before loading. Count backwards as they will move into lower depths if you start at the bottom!
private function loadContact(event:MouseEvent){
//add loader as above
for(var i:Number = numChildren-1 ; i >= 0 ; i–){
removeChildAt(i); //listeners not removed will still be an issue
}
myLoader.load(myContent);
}//loadContact


