Let’s assume that i have btn1, btn2 and btn3 inside a container mc on stage.
clickin’ on these btns i want to load a single swf for btn1 and 2 and clicking on btn3 i want to load 2 or more swf’s at the same time.
i have created an Array that contains the string values for the URL Requests and the function onClick()
in this function if i click on btn3 a for loop needs to create multiple instances of the loader object in order to load multiple files at the same time.
OK.
now my problem is: while when i toggle between btn1 and btn2 the new content .swf updates the old one leaving only one .swf on the stage (which is what i want!), when multiple swf’s are loaded then only one of them is removed from the stage when new content is loaded in, leaving some swf’s on stage and i don’t know how to remove them.
i think this is because i have created multiple instances of the loader object in the loop, but i don’t know how to target them in order to remove them from the stage when new swf’s are loaded.
here 's the code, any clue?
var XInitpos:Number = 0;
var Xpos:Number = 100;
var p1:String = "rollMenu2.swf";
var p2:String = "rollMenu3.swf";
var p3:String = "rollMenu4.swf";
var a:Array = new Array(p2, p3);
var loader:Loader = new Loader();
var scrollContainer:Sprite = new Sprite();
stage.addChild(scrollContainer);
container.addEventListener(MouseEvent.CLICK, onClick);
function onClick(event:MouseEvent):void {
trace(loaderArray);
if (event.target == container.btn1) {
trace("btn1 clicked.");
loader.load(new URLRequest("particles3.swf"));
addChild(loader);
loader.scaleX = .5;
loader.scaleY = .5;
loader.x = XInitpos;
//scrollContainer.removeChild(loaderArray[1]);
}
if (event.target == container.btn2) {
trace("btn2 clicked. go on!!!");
loader.load(new URLRequest("particles2.swf"));
addChild(loader);
loader.scaleX = .5;
loader.scaleY = .5;
loader.x = XInitpos;
}
if (event.target == container.btn3) {
for (var i:uint = 0; i < a.length; i++) {
loader = new Loader();
loader.load(new URLRequest(a*));
scrollContainer.addChild(loader);
loader.x = XInitpos;
XInitpos += 200;
}
}
}