I’m having trouble trying to get rid of an image in my container when I click on a thumbnail. I keep getting an error saying DisplayObject must be a child of the caller.
I’ve looked around the web and can’t figure out what I’m doing wrong, nor am I sure what the error means when its referencing the caller. Any help appreciated!
stop();
import fl.containers.UILoader;
import caurina.transitions.*;
//---------loading the external xml file-------
var urlRequest:URLRequest = new URLRequest("luxury.xml");
var urlLoader:URLLoader = new URLLoader();
var myXML:XML = new XML();
var xmlList:XMLList;
myXML.ignoreWhitespace = true;
urlLoader.addEventListener(Event.COMPLETE,fileLoaded);
urlLoader.load(urlRequest);
var featureURL:String = new String;
var main_content:Sprite;
var featureLoader:Loader;
var featureDesc:String;
//--------holds the paths to the thumbnails-------
var arrayURL:Array = new Array();
//--------holds the paths to the big photos-------
var arrayName:Array = new Array();
//--------holds the thumbnail objects-------
var holderArray:Array = new Array();
//--------represents the number of collumns-------
var nrColumns:uint = 2;
//-------represents the container of our gallery
var sprite:Sprite = new Sprite();
addChild(sprite);
var thumb:Thumbnail;
//-------- the thumbnails container-------
var thumbsHolder:Sprite = new Sprite();
sprite.addChild(thumbsHolder);
//-------- the photoLoader container-------
sprite.addChild(imageArea);
//-------- loads the big photo-------
var photoLoader:UILoader = new UILoader();
photoLoader.y = 30;
photoLoader.x = 10;
photoLoader.width = 550;
photoLoader.height = 330;
imageArea.addChild(photoLoader);
//-------load feature---------------
function loadFeature():void{
featureLoader = new Loader();
featureLoader.load(new URLRequest(featureURL));
featureLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImage);
}
function loadImage(event:Event):void{
imageArea.addChild(featureLoader.content);
featureLoader.content.x = 25;
featureLoader.content.y = 30;
imageArea.desc.text = featureDesc;
}
/* we loop through the xml file
populate the arrayURL, arrayName and position the thumbnalis */
function fileLoaded(event:Event):void {
myXML = XML(event.target.data);
xmlList = myXML.children();
ParseProperty(myXML);
loadFeature();
for (var i:int=0; i<xmlList.length(); i++) {
var picURL:String = xmlList*.img;
var picName:String = xmlList*.big_img;
arrayURL.push(picURL);
arrayName.push(picName);
holderArray* = new Thumbnail(arrayURL*,i,arrayName*);
holderArray*.addEventListener(MouseEvent.CLICK,onClick);
holderArray*.name = arrayName*;
holderArray*.buttonMode = true;
if (i<nrColumns) {
holderArray*.y = 65;
holderArray*.x = i*110+85;
} else {
holderArray*.y = holderArray[ i-nrColumns].y+110;
holderArray*.x = holderArray[ i-nrColumns].x;
}
thumbsHolder.addChild(holderArray*);
}
}
/* Featured Loop */
function ParseProperty(propertyInput:XML):void {
var findFeature:XMLList = propertyInput.house.(featured == "Yes");
var fURL:String = findFeature.big_img;
var fDesc:String = findFeature.desc;
featureURL = fURL;
featureDesc = fDesc;
trace(fURL);
}
//----handles the Click event added to the thumbnails--
function onClick(event:MouseEvent):void {
var featureLoader:Loader = Loader(event.target);
imageArea.removeChild(featureLoader.content);
featureLoader.unload();
photoLoader.source = event.currentTarget.name;
gotoAndStop("2");
}