reading values from xml file in actionscript 3 into a combobox -
my layout in .mxml file this:-
<?xml version="1.0" encoding="utf-8"?> <s:windowedapplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="600" height="800" > <fx:declarations> <!-- place non-visual elements (e.g., services, value objects) here --> </fx:declarations> <mx:hbox width="100%" horizontalalign="right" top="20"> <mx:combobox id="combobox" fontsize="12" width="10%" dataprovider="{middlestack}" name="versioncombo"/> </mx:hbox> <mx:vbox top="50" left="10" > <mx:label text="builds" fontsize="18"> </mx:label> </mx:vbox> <mx:vbox top="50" horizontalalign="center" left="200"> <mx:label text="date" fontsize="18"> </mx:label> </mx:vbox> <mx:vbox top="50" horizontalalign="center" right="10"> <mx:label text="release" fontsize="18"> </mx:label> </mx:vbox> <mx:vbox height="100%" width="100%" stylename="centerlightgreybg" verticalgap="0"> <mx:viewstack id="middlestack" width="100%" height="100%" backgroundalpha="0" change="changev()"> </mx:viewstack> </mx:vbox> <fx:style>
now want add values combo box id = combobox , name = versioncombo reading values xml file. xml this.
<install> <version> <number>5.0</number> <build>907681</build> <path></path> </version> <version> <number>6.2</number> <build>1043305</build> <path></path> </version> </install>
i want populate combo box version number i.e 5.0,6.2.
i tried follow link not able http://www.parorrey.com/blog/flash-development/as3-adding-dropdown-combobox-flash-component-using-actionscript-with-xml-data/
as3 procedural. randomise order of items in combobox xml
i new air.
i tried this:-
import fl.data.dataprovider; var country:string=''; var countrieslist:array = []; //urlloader class helps load data external source such url var xmlloader:urlloader ; var xmldata:xml = new xml(); public function pathfinding() { // constructor code xmlloader = new urlloader(); xmlloader.addeventlistener(event.complete, loadxml); xmlloader.load(new urlrequest("grid.xml")); } function loadxml(e:event):void { xmldata = new xml(e.target.data); xmldata.ignorewhite = true; parsecountries(xmldata); //trace(xmldata); } function parsecountries(countriesinput:xml):void { var countrieslisting:xmllist = countriesinput.country.attributes(); var i:int; each (var countryname:xml in countrieslisting) { //populate countrieslist array used combobox countrieslist.push( {label:countryname, data:countryname} ); trace(countryname); } versioncombo.prompt = "select version:"; versioncombo.dataprovider = new dataprovider(countrieslist); versioncombo.addeventlistener(event.change, dropdownhandler); versioncombo.dropdown.rowheight = 30; versioncombo.width = 150; } function dropdownhandler(event:event):void { country = combobox(event.target).selecteditem.data; trace("selected country: "+ country); //do here whatever want } combobox.prompt = "select country:"; combobox.dataprovider = new dataprovider(countrieslist); combobox.addeventlistener(event.change, dropdownhandler); combobox.dropdown.rowheight = 30; combobox.width = 150;
but getting error "-1180: call possibly undefined method dataprovider."
combobox.dataprovider = new dataprovider(countrieslist);
not working me.
you need read about correct work dataprovider. didn't need new instance creation, "new dataprovider". please, use arraycollection or of ilist
Comments
Post a Comment