In the following code block if I debug the and look at the var obj.theID it shows as an XMLList. Even though the code traces properly I feel it should be a string not an XMLList.
So my question is how can I get it to assign a string and not an XMLList?
var myXML:XML = new XML(
<panels>
<panel id="1"/>
<panel id="2"/>
<panel id="3"/>
</panels>
);
var panels:XMLList = new XMLList( myXML.children());
trace( panels.length()); // is as expected
for each( var panel:XML in (new XMLList( myXML.children())) ){
var obj:Object = new Object( );
// XMLList is assigned here but why? and how can I make it a string?
obj.theID = panel.@id;
// id is traced as expected but apparently it is just converting the XMLlist to a string.
trace( panel.@id)
}
The AS3 xml parser simply reads any native xml content, either attribute or node data as a string, and can be used as such without type conversion. Which is one of things that makes xml so convenient in flash. But if you check the type, it will return as XML unless you specifically cast it (which is essentially what toString() does).
— update —
Of note = XML and XMLlist can be and often are used interchangeably. They each have access to a similar set of methods, but there is an important difference. XML may have exactly one root node, while XMLlist may have several. This may not make much of a difference in normal usage, but depending on the structure of your incoming xml, may be a critical distinction. Normally, I just use the XML type. Here is a good article on xml vs xmllist.
Cheers