XML nausing me up

Hi,

As stated the other day, XML is something I ignored until recently, now that I see how useful it is I shall be using it all the time.

I made my first XML gallery yesterday, and now I’m just polishing it up.

I have a problem though. I’m loading thumbnails into holders in the XML onLoad loop, and I am also assigning the holder a preloader.

Now this worked perfectly in another non XML loop, with the exact same preloader function etc.

In the XML loop it doesn’t. When the preloader is assigned to the holder, it hasn’t yet registered that a JPG is being loaded into it, it is preloading what it thinks is just an empty MC, and thus sets percentloaded to 100, and the preloader is void.

Now this can be fixed fairly easily by making another loop a few frames down the timeline, to give it time to register that something is being loaded into the holder.

However, I don’t want to do this, it’s stupid, I want to keep things nice and neat all in 1 loop.

For you XML savvy kirupians, what else can I do? I’m a bit confused because I thought the XML onLoad function was to prevent hiccups like this.

Any idea of what I can do other than having to create another loop to load the thumbs a few frames down?

Here is the XML loop…

xml.onLoad = function(loaded) {
 if (loaded) {
  total = this.firstChild.childNodes;
  for (var i = 0; i<total.length; i++) {
   description.push(total*.firstChild.firstChild);
   thumbs.push(total*.firstChild.nextSibling.firstChild);
   bigpics.push(total*.firstChild.nextSibling.nextSibling.firstChild);
   if (i%4 == 0) {
    b = 0;
    c++;
   }
   initObj = {_x:h_pos+b*h_spacing, _y:v_pos+c*v_spacing};
   bob = attachMovie("thumb", "thumb"+i, i, initObj);
   thumbholders.push(bob);
   bob.holder.loadMovie("thumbs/"+thumbs*);
   bob.id = i;
   thumbloader(bob);
   bob.onRollOver = function() {
    testbox.text = this.id;
    this.gotoAndStop(2);
   };
   bob.onRollOut = function() {
    this.gotoAndStop(1);
   };
   bob.onRelease = function() {
    hidethumbs();
    bigholder.holder.loadMovie("thumbs/"+bigpics[this.id]);
    bigloader(bigholder);
   };
   b++;
  }
 }
};
xml.load("illustration.xml");

By the way, how do some of you paste the code with the AS colourcoding in tact? Surely you don’t do this manually? :slight_smile:

Cheers,
Joe

AS FORMATTING:
when posting - just wrap any items you want to appear formatted as action script with:

open bracket+“as”+close bracket
then your code goes here:
open bracket+slash+“as”+close bracket

LOADMOVIE:
Look into using the MovieClipLoader class versus loadMovie… I may get some fire from saying this, but loadMovie is horrible… the moviecliploader class contains methods for checking progress.

[ot][noparse][noparse][/noparse][/noparse] allows you to post tags like [noparse]


[/noparse] by the way.[/ot]

Thanks creatify, unfortunately it didn’t work, the same thing happened, it didn’t recognise that a JPG was being loaded into the target MC by the time the preloader was called. I can’t see any way round it but delaying loading the images in from XML.

At what point do you call your preloader once an image from XML is loaded in?

Incidentally, these 2 bits of code do the same thing - which is preferable?


total = this.firstChild.childNodes;
		for (var i = 0; i<total.length; i++) {
			description.push(total*.childNodes[0].firstChild.nodeValue);
			thumbs.push(total*.childNodes[1].firstChild.nodeValue);
			bigpics.push(total*.childNodes[2].firstChild.nodeValue);
}


total = this.firstChild.childNodes;
		for (var i = 0; i<total.length; i++) {
			description.push(total*.firstChild.firstChild);
			thumbs.push(total*.firstChild.nextSibling.firstChild);
			bigpics.push(total*.firstChild.nextSibling.nextSibling.firstChild);
}

I was thinking the first one, logically, as if each element had many childNodes, you’d end up writing nextSibling 10 times.

How odd. The above code works perfectly, preloader n’ all, with just one amendment.

bob.createEmptyMovieClip(“holder”, 1);

Before bob.holder.loadMovie

Instead of having the holder MC already there, I generate it in the XML loop and it works. I don’t understand why though, why would an XML loop take longer to target an existing MC, and a normal, non XML loop doesn’t.

why don’t you simply use a class to parse automatically the xml?

http://www.sephiroth.it/file_detail.php?id=134

Pier, how would it help me in this instance?

You would not have to parse your xml by hand… don’t you think that’s helpful?

Oh I see I see, so you’re referencing my question about which parsing method is preferable, rather than my original issue?

OK sure, I’ll try it out.

Im not used to using classes like this, I’m a Flash MX boy, I’m used to having to code my own tweens etc, only recently have I even started to use tween engines :smiley:

I’m still settling in to this new Flash era.

Thanks for the info.

Don’t know if I mised anything but what does thumbs*return when traced?

Nathan - it returns the list of JPG names :slight_smile: