container issue
Hey. I posted a question on this before, but couldnt get a reply, problably too much code, so I thought I would try again but try to cut down on things. Basically, I load images from an xml file, and then use this method to add them each to their own container
function urlLoaded(event:Event):void {
urlLoader.removeEventListener(Event.COMPLETE,urlLoaded);
xml=XML(event.target.data);
xmlList=xml.children();
for (var i:int=0; i<xmlList.length(); i++) {
var thumb:Thumbnail=new Thumbnail(xmlList.url);
arrayThumb.push(thumb);
arrayThumb.y=150.5;
arrayThumb.x=i*110+280;
photoContainer.addChild(thumb);
arrayThumb.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
arrayThumb.addEventListener(MouseEvent.MOUSE_UP, dropIt);
}
}
I basically want to reuse all this code from many events, so in order to do this, I need to clear all my containers if they are holding an image. Just for info, photoContainer is a sprite, and added directly to the stage. arrayThumb is an array holding images to be displayed. So, too empty the array, and to remove all the containers, I am trying
function click_handler(event_object:MouseEvent) {
if(photoContainer.getChildByName("thumb") != null){
while(arrayThumb.length > 0) {
arrayThumb.pop();
}
loadXML("pics.xml");
}
else{
loadXML("pics.xml");
}
}
My thinking behind this was if photoContainer has any children named "thumb", it should remove all photoContainers (didnt know how to do this). It should also remove all elements of array, then it should call loadXML. I think I am on the right tracks on removing all the photoContainers if any exist, but how can I get rid of them?
cheers
Additionally, it never appears to even go into the if statement, even if a photoContainer exist, so think this might be slightly wrong aswell.