Skip to main content
Participant
September 11, 2008
Question

How to get XML child number

  • September 11, 2008
  • 2 replies
  • 343 views
In AS2 you could use numChildren to get the number of children in a given XML file, whats the equivalent in AS3? Ive tried using var myNum:Number = myXMLname.numChildren , but when I trace it I just get 0.
Thanks
This topic has been closed for replies.

2 replies

Participant
September 11, 2008
Working now, thanks.
ropeGun
Inspiring
September 11, 2008
You need to call a method these days:

Say you have an XML Object like the following:

var myXMLExample:XML =
<EXAMPLE>
<ITEM>
<FRUIT>Apple</FRUIT>
</ITEM>
<ITEM>
<FRUIT>Kiwi</FRUIT>
</ITEM>
<ITEM>
<ANIMAL>Fruitbat</ANIMAL>
</ITEM>
</EXAMPLE>

trace(myXMLExample.ITEM.length()); //since there are three ITEMS
trace(myXMLExample.ITEM.FRUIT.length()); //since there are only two ITEMS with FRUIT
//first trace gives you: 3
//second trace gives you: 2