How to add pictures to a container Sprite with forEach and progress bar?

Bouctioli

New Member
I am successful in loading a single image and creating it using addChild(). Now I am trying to load multiple images into a sprite "Container" using a forEach loop increasing the X value for each image so they are displayed in a row. The imageloader is referenced to linkage within an XML document. If I testrun this code, this error pops up at the point when the image is loaded and I try to removeChild() the loadBar Animation.\[code\]ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.at flash.display::DisplayObjectContainer/removeChild()\[/code\]Here is the AS3:\[code\]private function loadBG():void{ var artGrab:Number=0; var artX:Number=0; for each (var albumData:XML in mainXML.artist[artistID].album) { imgURL = new URLRequest(mainXML.artist[artistID].album[artGrab].art); imgLdr = new Loader(); //if you're loading a bigger image or need a preloader imgLdr.contentLoaderInfo.addEventListener(Event.COMPLETE,onBGLoaded); imgLdr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onLoading); //add loader animation "All Loader" ldrAnim = new AllLoader(); albumContainer.addChild(ldrAnim); ldrAnim.x = artX; ldrAnim.y=200; imgLdr.load(imgURL); artGrab++; artX+481; ldrAnim.x+481; } }private function onLoading(evt:ProgressEvent):void{ var bytesToLoad:Number=imgLdr.contentLoaderInfo.bytesTotal; var numberLoaded:Number=imgLdr.contentLoaderInfo.bytesLoaded; ldrAnim.progBar.scaleX = numberLoaded/bytesToLoad; var loadedPercent=Math.round(numberLoaded/bytesToLoad*100); ldrAnim.progPercent.text = loadedPercent +" %"; trace("Loading..."+loadedPercent +"%"); }private function onBGLoaded(evt:Event):void{ trace("image loaded!"); //image setup addChildAt(imgLdr,0); //now that its 100% loaded, you can resize it , etc. removeChild(ldrAnim); //use cross multiplying of fractions to maintain aspect ratio var origW = imgLdr.contentLoaderInfo.width; var origH = imgLdr.contentLoaderInfo.height; trace("orig width: "+origW+ "orig height: "+origH); //set new width imgLdr.width = 481; var newH:Number = 481*origH/origW; imgLdr.height = newH; //may wish to do positioning AFTER resizing imgLdr.x=stage.stageWidth/2-imgLdr.width/2; imgLdr.x=0; imgLdr.y=0; imgLdr.width=480; imgLdr.height=480; imgLdr.alpha=1; imgLdr.z=0; }\[/code\]Bless you for reading this all, I don't understand what is causing this error so comments are appreciated!
 
Back
Top