I am having this error, not sure why it appears, i believe its something with scope problem. Because i have added Child already. I can't even remove Child, the child is added within the loop, and i am not sure how to manipulate the childs that were added within the loop from the outside(after the loop has ended).
I am trying to add the child from within the loop to a viewport, but i am demonstrating the problem with removeChild to reduce the complication. Because i am trying to locate the reason of why it is giving me this error, and trying to learn what i should do.
Thanks for your time!
for (var j:int = 5; j < somedata.length; j++)
{
if(somedata[j]){
var myLoader:Loader = new Loader();
var image:Bitmap;
var url:URLRequest = new URLRequest("http://www.rentaid.info/rent/"+somedata[j]);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
myLoader.load(url);
function onImageLoaded(e:Event):void {
image = new Bitmap(e.target.content.bitmapData);
var mw:Number = bf.width*2;
var mh:Number = bf.height*1.2;
image.y = bf4.y+25;
/* if you set width and height image same with the stage use this */
image.width = mw;
image.height = mh;
var _contentHolder: Sprite;
addChild(_contentHolder);
_contentHolder.addChild(image);
}
}
removeChild(_contentHolder);
}
Edit:
function LoadImages() : void {
for (var j:int = 5; j < somedata.length; j++) {
var image:Bitmap;
myLoader = new Loader;
var urlRequest : URLRequest = new URLRequestfor ("http://www.rentaid.info/rent/"+somedata[j])
myLoader.load(urlRequest);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadComplete);
}
}
function LoadComplete(event : Event) {
_contentHolder.addChild(image);
}
Or something like this?
var loadedArray:Array = new Array();
var counter:int=0;
function loadImage():void{
var loader:Loader = new Loader();
var image:Bitmap;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
loader.load(new URLRequest("http://www.rentaid.info/rent/"+somedata[counter]));
function onImageLoaded(e:Event):void {
image = new Bitmap(e.target.content.bitmapData);
loadedArray.push(e.target.content);
if(counter == somedata.length-1){
for(var i:uint = 5; i < somedata.length; i++){
image[i].x = 0 + i * 100;
addChild(_contentHolder);
_contentHolder.addChild(image[i]);
currentY += _contentHolder.height + 10;
}
}
else{
counter++;
loadImage();