how do I unload images from this function?:
private function loadImage():void
{
var spacing:int = 10;
if(_array.length > 0)
{
var loader:Loader = new Loader();
Main.instance.workinfobox.rect.addChild(loader);
var request:URLRequest = new URLRequest(_array[0].path); //Loads first item in the array each time.
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
loader.y = _lastY + _lastHeight + spacing;
if(starting == true){
loader.y += 150;
}
loader.load(request);
_lastY = loader.y; //We set after so we are ready for the next.
_array.shift(); //Remove the first item from the array.
starting = false;
}
}
function onImageLoaded(e:Event):void
{
_lastHeight = e.target.height;
loadImage(); //Attempt to load another image if the array isn't empty.
}
}