Both suggestions so far have what I consider a bad choice.  That is to use
resultFormat="object" which is the default.  This setting converts your xml
into a tree of dynamic objects.  This has many drawbacks.  

I advise setting resultFormat="e4x" which will preserve the xml you get from
the server.

Private function onResult(event:ResultEvent):void
 Var xmlResult:XML = XML(event.result);
 xlDesigners:XMLList = xmlResult.designer;
 trace(xlDesigners.toXMLString());  //is this what you expect?
 myCombo.dataProvider = xlDesigners;

And you will need to set the ComboBox labelField="@name"

Tracy Spratt,
Lariat Services, development services available

-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Fidel Viegas
Sent: Monday, March 23, 2009 5:56 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Bind ComboBox to returning XML (HOW TO)

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
<b.j.wildb...@massey.ac.nz> 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: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
> Behalf Of Matthew A. Wilson
> Sent: Tuesday, 24 March 2009 8:12 a.m.
> To: flexcoders@yahoogroups.com
> 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-1e62
079f6847
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links





Reply via email to