When you get a elements from an XML object through e4x it return an XMLList.

The following would throw an error:

var data:XML = <data>
<img src="jpg/cinematic001.jpg" />
<img src="jpg/cinematic002.jpg" />
<img src="jpg/cinematic003.jpg" />
</data>;

var imgs:XML = data.img;

//output:
TypeError: Error #1034: Type Coercion failed: cannot convert xmll...@4a24d91 to 
XML.


The following works:

var data:XML = <data>
<img src="jpg/cinematic001.jpg" />
<img src="jpg/cinematic002.jpg" />
<img src="jpg/cinematic003.jpg" />
</data>;

var imgs:XMLList = data.img;

trace("num nodes: ", imgs.length());
trace(imgs.toXMLString());


// output
num nodes:  3
<img src="jpg/cinematic001.jpg"/>
<img src="jpg/cinematic002.jpg"/>
<img src="jpg/cinematic003.jpg"/>


An XML object has a length of 1, while an XMLList has a length matching the number of nodes, which could be 1, in which case you can treat it as XML :).
From the docs:

<quote>
   If an XMLList object has only one XML element, you can use the XML class 
methods on the XMLList object directly.
   If you attempt to use XML class methods with an XMLList object containing 
more than one XML object, an exception is thrown;
instead, iterate over the XMLList collection (using a for each..in statement, for example) and apply the methods to each XML object in the collection.
</quote>

Just think of an XMLList as an Array of XML nodes.
Actually, you use the "Array access operator" (which is a fancy way of saying "square brackets") to access nodes in an XMLList object:

var data:XML = <data>
<img src="jpg/cinematic001.jpg" />
<img src="jpg/cinematic002.jpg" />
<img src="jpg/cinematic003.jpg" />
</data>;

var imgs:XMLList = data.img;
trace(imgs[...@src);

// output:
jpg/cinematic001.jpg

regards,
Muzak

----- Original Message ----- From: "Cor" <c...@chello.nl>
To: "'Flash Coders List'" <flashcoders@chattyfig.figleaf.com>
Sent: Sunday, July 26, 2009 10:58 AM
Subject: RE: [Flashcoders] Image loader problem


Thank guys!!!

It is an eye opener to see all kinds of different approaches.
I will definitely look at the bulkloader but Muzak's method makes a lot of 
sence to me in my project for now.

@Muzak,

I normally only use the XML class.
I notice you using XMLList.
Could you explain when XML is appropriate and when to use XML.
I read the help, but this does not explain the nitty-gritty.

Thanks again!!

Cor

PS. I love this list



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to