Mega Code Archive

 
Categories / Flex / Data Model
 

Looping over an XML structure using its index

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"     backgroundColor="white" creationComplete="tryme()">     <mx:XML id="usersXML">         <root>             <users>                 <user id="1" lovesDonuts="Yes">                     <firstname>T</firstname>                     <lastname>A</lastname>                 </user>                 <user id="2" lovesDonuts="Yes">                     <firstname>J</firstname>                     <lastname>H</lastname>                 </user>             </users>         </root>     </mx:XML>     <mx:Script>                  [Bindable]         public var infoString:String = "";         public function tryme():void         {             for(var i:int=0; i<usersXML.users.user.length(); i++)             {                 infoString = infoString + usersXML.users.user[i].firstname;                 infoString = infoString + usersXML.users.user[i].lastname;             }         }            </mx:Script>     <mx:TextArea text="{infoString}" width="250" height="100" /> </mx:Application>