Try adding a toString() to your xml manipulation. If you were to debug and do something like var o : Object = x.it...@prop1 you would find that it is not a String. So just add a toString() like [email protected](). Do that for all of your xml attributes when getting them. I'm not sure if there is a better best practice but this is what I do.
Dale -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of David Sent: Sunday, September 06, 2009 2:22 PM To: affug Subject: [AFFUG Discuss] Parsing XMLList question Hey yall, This seems like a pretty simple problem, which makes it all the more frustrating that I can't get it to work right: There is an XMLList of items, each item has three properties: prop1, prop2, and prop3. There are two TextAreas, t1 and t2. t1 displays the XMLList.toString t2 is blank There are two buttons: Show and Clear. When you click Show, the following should happen: For each item in the XMLList, if prop3 is false and prop1 is "BB", then add that item's prop2 to the text of t2. My code is below. It's only showing some of the results, not all expected. (It should show L3a and L3y. It only shows L3y.) What am I doing wrong? === <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ [Bindable] private var xmlList:XMLList = <> <item prop1="AA" prop2="L0" prop3="true" > <item prop1="AA" prop2="L1a" prop3="true" > <item prop1="AA" prop2="L2a" prop3="true" > <item prop1="BB" prop2="L3a" prop3="false" /> <item prop1="AA" prop2="L3b" prop3="false" /> </item> </item> <item prop1="AA" prop2="L1b" prop3="true" > <item prop1="AA" prop2="L2x" prop3="true" > <item prop1="AA" prop2="L3x" prop3="false" /> </item> <item prop1="AA" prop2="L2y" prop3="true" > <item prop1="BB" prop2="L3y" prop3="false" /> </item> </item> </item> </>; private function showBBs():void{ lookForBBs(xmlList.children()); } private function lookForBBs(list:XMLList):void{ for each (var x:XML in list){ if (x.it...@prop3 == "false"){ if (x.it...@prop1 == "BB"){ t2.text += x.it...@prop2+"\n"; } } else{ lookForBBs(x.children()); } } } ]]> </mx:Script> <mx:HBox width="100%" height="100%"> <mx:TextArea id="t1" text="{xmlList.toString()}" width="100%" height="100%"/> <mx:Button label="Show" click="showBBs()"/> <mx:Button label="Clear" click="{t2.text=''}"/> <mx:TextArea id="t2" text="" width="100%" height="100%"/> </mx:HBox> </mx:Application> === Thanks! -David ------------------------------------------------------------- To unsubscribe from this list, simply email the list with unsubscribe in the subject line For more info, see http://www.affug.com Archive @ http://www.mail-archive.com/discussion%40affug.com/ List hosted by http://www.fusionlink.com ------------------------------------------------------------- ------------------------------------------------------------- To unsubscribe from this list, simply email the list with unsubscribe in the subject line For more info, see http://www.affug.com Archive @ http://www.mail-archive.com/discussion%40affug.com/ List hosted by http://www.fusionlink.com -------------------------------------------------------------
