|
I want to get the first element of my "tmps" xml document. Casting the string to a XML document and work on it as a XMLList prevents me from getting the first element in the XMLList as long as the element doesn't contain a child! That simply must be a bug. |
<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.*; import flash.events.*; private var work:String = "<tmps><tmp att=\"abc\"><dummy/></tmp></tmps>"; private var wontWork:String = "<tmps><tmp att=\"abc\" /></tmps>"; private function init() : void { result.text = work; } private function clickHandler(event:ItemClickEvent):void { if (event.label == "OK") { result.text = work; } else { result.text = wontWork; } } private function printResult(event:MouseEvent):void { var list :XMLList = XML(result.text).tmp; Alert.show(list[0]); // should print first element in the list - the tmp element } ]]> </mx:Script> <mx:Panel title="Flex bug example" height="100%" width="100%"> <mx:ButtonBar itemClick="clickHandler(event);"> <mx:dataProvider> <mx:Array> <mx:String>OK</mx:String> <mx:String>not OK</mx:String> </mx:Array> </mx:dataProvider> </mx:ButtonBar> <mx:TextArea id="result" editable="false" height="100" width="100%"/> <mx:Button id="evaluate" label="evaluate result" click="printResult(event)"/> </mx:Panel> </mx:Application> |