Hey there, I know a few threads existed that talked about this error, but none of them seemed to fit my problem.
This is my first attempt at a dynamic flash file and I was able to my other errors but I’m stuck on this one. The output tells me this:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::LoaderInfo@25183701 to flash.display.DisplayObject.
at samples_display_fla::MainTimeline/imageLoaded()
Here is my code so far:
var mainPopArray:Array = new Array();
var descriptArray:Array = new Array();
var titleArray:Array = new Array();
var imagePathArray:Array = new Array();
var pcounter:int=1;
var dataPath:String="sample_data.xml";
//this sets up flash to load the xml into flash
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
//init
xmlLoader.addEventListener(Event.COMPLETE, loadXML);
xmlLoader.load(new URLRequest(dataPath));
//functions
function loadXML(e:Event ):void {
//check if function fired
trace("fire loadXML");
xmlData=new XML(e.target.data);
//creates variables for the xml text
//check load item from file
trace(xmlData.sample[0].descript[0].text());
descriptArray.push(xmlData.sample[0].descript[0].text());
//descriptionArray.htmlText=xmlData.sample[0].descript[1].text();
//descriptionArray.htmlText=xmlData.sample[0].descript[2].text();
//check load item from file
trace(xmlData.sample[0].image[0].text());
imagePathArray.push(xmlData.sample[0].image[0].text());
//imagePathArray.push(xmlData.sample[0].image[1].text());
//imagePathArray.push(xmlData.sample[0].image[2].text());
//check load item from file
trace(xmlData.sample[0].pTitle[0].text());
titleArray.push(xmlData.sample[0].pTitle[0].text());
//titleArray.htmlText=xmlData.sample[0].pTitle[1].text();
//titleArray.htmlText=xmlData.sample[0].pTitle[2].text();
//checking all array lengths
trace(descriptArray.length);
trace(imagePathArray.length);
trace(titleArray.length);
//use function to create pops once data loaded
createPops();
}
function createPops():void {
//creating each page of the sample
for (var i=0; i<descriptArray.length; i++) {
trace("in");
var myPop:Pop = new Pop();
mainPopArray.push(myPop);
addChild(myPop);
myPop.mcText.txt_descrip.htmlText=descriptArray*;
myPop.mcText.txt_title.htmlText=titleArray*;
loadImage(imagePathArray*);
}
//set initial pop
hideAllPops();
mainPopArray[0].visible=true;
mainPopArray[0].gotoAndStop(15);
txt_pcounter.text=pcounter+"/"+mainPopArray.length;
}
function hideAllPops():void {
for (var i=0; i<mainPopArray.length; i++) {
mainPopArray*.visible=false;
}
}
function loadImage(iName:String):void {
trace("fire loadImage");
// Set properties on my Loader object
var imageLoader = new Loader();
imageLoader.load(new URLRequest(iName));
//imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
}
function imageLoaded(e:Event):void {
trace("fire Loaded")
mainPopArray[mainPopArray.length-1].mcContainer.addChild(e.target);
}