PDA

View Full Version : XML/loop trouble


kjeft
08-06-2008, 08:03 PM
What's wrong?
I simply want the timer to loop endlessly through my externally loaded captions and show them in my captxt textbox.

And also, how do I display photos from my XML file?

Any help would be greatly appreciated!


var loader:URLLoader = new URLLoader();
var xml:XML;
var timer:Timer = new Timer(5000);
var i:int = 0;

loader.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("photos.xml"));

function onLoaded(e:Event):void {
xml = new XML(e.target.data);
var xmlList:XMLList = xml.photo;
captxt.text = xmlList.captions[i];
}

timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();

function onTimer(e:TimerEvent):void {
if (i < xml.photos.length) {
i++;
onLoaded();
} else {
i = 0;
}
}

DiamondDog
08-06-2008, 08:24 PM
I'm pretty sure the problem is in the way that you've defined your timer.

Thisvar timer:Timer = new Timer(5000);

means your timer will fire once, and once only, and that will happen after 5 seconds.

I'm guessing you want your timer to repeatedly fire.

If you define your timer like this
var timer:Timer = new Timer(5000,0); it should fire repeatedly (and indefinitely until you stop() it).

kjeft
08-06-2008, 08:34 PM
Thank you

There's something about my onTimer function that's not right and I can't figure it out. is the "if/else" loop the wrong one to use?


ow it's so annoying to be a newbie!