Here is another alternative:
declare an HTTPService like this:
<mx:HTTPService
id="listService"
url="path/to/list.jsp"
method="POST"
showBusyCursor="true"
fault="onFault(event);"
result="onResult(event);"
useProxy="false"/>
and an array collection
<mx:ArrayCollection id="designerAC"/>
and in your actionscript you create the following handler:
private function onResult(event : ResultEvent) : void {
if (event.result.response.designers == null ||
event.result.response.designers.designer == null) {
designerAC = new ArrayCollection(); // empty array collection
} else if (event.result.response.designers.designer is ObjectProxy) {
designerAC = new
ArrayCollection([event.result.response.designers.designer]);
} else {
designerAC = event.result.response.designers.designer as ArrayCollection;
}
}
and your combo box would look like something like this:
<mx:ComboBox dataProvider="{designerAC}" labelField="name"/>
That should give you an idea.
Hope that helped
Fidel.
On Mon, Mar 23, 2009 at 10:23 PM, Wildbore, Brendon
<[email protected]> wrote:
> Here’s an example of one way of doing that.
>
>
>
> Assuming you xml comes from a webservice or httpservice call and you want
> your combobox dataprovider bound to a variable comboboxAC you could try the
> following function onResult.
>
>
>
>
>
> private function onResult( event:ResultEvent ):void{
>
> // put xml into array
>
> var returnedData:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(
> event.result ) );
>
>
>
> // loop over result array and create a new object
> for each xml item
>
> for (var i:uint = 0;i<returnedData.length;i++){
>
> // create object
>
> var obj:Object = new Object();
>
> obj.label=returnedData[i].name;
>
> obj.data=returnedData[i].id;
>
> // add item to combobox dataprovider
>
>
> comboboxAC.addItem(obj);
>
> }
>
> }
>
>
>
> T
>
>
>
> ________________________________
>
> From: [email protected] [mailto:[email protected]] On
> Behalf Of Matthew A. Wilson
> Sent: Tuesday, 24 March 2009 8:12 a.m.
> To: [email protected]
> Subject: [flexcoders] Bind ComboBox to returning XML (HOW TO)
>
>
>
> Need help with a combobox...
>
> I have a combobox that I want to load from a database. The text will be a
> name, and the value will be an integer.
>
> That's it - pretty straightforward. Just can't seem to figure it out. The
> xml will look like this:
>
> <designers>
> <designer id="1" name="Matt" />
> <designer id="2" name="Ted" />
> </designers>
>
> Thanks so much in advance for your help!!!
>
>
------------------------------------
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Alternative FAQ location:
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo!
Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[email protected]
mailto:[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/