PDA

View Full Version : Trouble loading XML file.Please help me!



ecptavares
February 18th, 2008, 07:22 AM
Hi!

I have a xml file with this structure :



<?xml version="1.0" encoding="ISO-8859-1"?>
<slideshow>
<photo thumb="images\foto1.jpg" url="images\foto1.jpg" caption="DJ Chambinho fazendo o Gas Total."/>
<photo thumb="images\foto1.jpg" url="images\foto2.jpg" caption="DJ Chambinho mixando no Gas Total."/>
<photo thumb="images\foto1.jpg" url="images\foto3.jpg" caption="DJ Pele,Emersom(Barriga),Danielle e DJ Chambinho na Vintage."/>
<photo thumb="images\foto1.jpg" url="images\foto4.jpg" caption="DJ Chambinho e sua linda mulher, DJ Gabriela, na Joy."/>
<photo thumb="images\foto1.jpg" url="images\foto5.jpg" caption="Entrada do Olympia Disco Show."/>
<photo thumb="images\foto1.jpg" url="images\foto6.jpg" caption="Pista de danca do Olympia Disco Show."/>
</slideshow>
and I am trying to load each image into an empty MC but it is not working. I am sure there is something wrong with my code.Could You guys help me out?


import flash.events.*;

stop();

var xLoader : URLLoader = new URLLoader();
var xml : XML;

xLoader.addEventListener(Event.COMPLETE,onComplete );
xLoader.load(new URLRequest("album.xml"));

function onComplete(e:Event):void
{
xml = new XML(e.target.data);
var lista :XMLList = xml.slideshow.photo;
holder.addChild(lista[0]);
}

What is wrong and what else I need to do?

pou-pou
February 18th, 2008, 08:41 AM
var imageLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("album.xml"));

xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void
{
xml = XML(event.target.data);
xmlList = xml.children();
for(var i:int = 0; i < xmlList.length(); i++)
{
imageLoader = new Loader();
imageLoader.load(new URLRequest(xmlList[i].attribute("thumb")));
// imageLoader.x = 25; // positionings
// imageLoader.y = i * 150 + 25;
addChild(imageLoader);

}

}

jwopitz
February 18th, 2008, 10:28 AM
You guys, e4x is so powerful. For any node in for loop you can just the dot@ syntax like below:



function xmlLoaded(event:Event):void
{
xml = XML(event.target.data);
xmlList = xml.children();
var obj:Object;
for each (obj in xmllist)
{
imageLoader = new Loader();
imageLoader.load(new URLRequest(obj.@thumb));
// imageLoader.x = 25; // positionings
// imageLoader.y = i * 150 + 25;
addChild(imageLoader);

}

}