Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-17-2006, 03:57 PM   #1
smakwam
Registered User
 
Join Date: Aug 2006
Posts: 1
Default populate list and combobox from xml

Hi all,
first time here so apologies for any mistakes ....
I am playing around with flex 2 and PHP. I have one page with a list box and a combo box on seperate panels. I am trying to populate both of these using a PHP backend which generates XML. The XML generation works beautifully as does the list box. My problem is that the combobox does not get populated, all i can see when running the app is [object Object] in the combobox !!!. the number of [object Object] match the number of items that are in the list box. I am sure it's a silly mistake on my part but being new to this I am not sure how to solve it. I have searched Google all day without success. Most of the examples hard code the array and if they do not, they use list boxes which is not what I am after. Perhaps there is no solution ....
Below is the mxml code.
Thanks in advance for any assistance you can provide.
Regards
Smakwam


/************************************************** *******
code start

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"

width="390" height="430"
creationComplete="bs.send();"
>
<mx:Script>

<![CDATA[
import mx.managers.CursorManager;
import mx.rpc.events.InvokeEvent;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;

[Bindable]
private var bloggersCol:ArrayCollection;

[Bindable]
private var bloggersCol2:ArrayCollection;

// Gets called when HTTPService is invoked to
// request the XML.
private function bsInvokeHandler(event:InvokeEvent):void

{
// Display the busy cursor
CursorManager.setBusyCursor();
}

// Gets called when the XML is successfully loaded.
private function bsResultHandler(event:ResultEvent):void

{
// Save a reference to the list of bloggers
bloggersCol = event.result.root.restaurant_category;

//bloggersCol2 = event.result.root.restaurant_category.name;
// Hide the busy cursor
CursorManager.removeBusyCursor();
}


private function bsFaultHandler(event:FaultEvent):void
{

// There was an error in loading the XML
Alert.show (event.fault.message);

// Hide the busy cursor
CursorManager.removeBusyCursor();
}
]]>

</mx:Script>

<!-- Service to load in XML -->
<mx:HTTPService
id="bs"
url="http://localhost/phpxml3.php"

invoke="bsInvokeHandler(event);"
result="bsResultHandler(event);"
fault="bsFaultHandler(event);"

/>

<mx:Panel title="Bloggers we love!" width="100%">
<mx:List
id="bloggersList" width="100%" rowCount="4"
dataProvider="{bloggersCol}"
labelField="name"
/>
<mx:ControlBar horizontalAlign="center">
<mx:Button
label="Add a blogger!"
click="bloggersCol.addItem({name:'Pete-Barr Watson', url:'http://petebarrwatson.com/'});"
/>
</mx:ControlBar>
</mx:Panel>

<!--<mx:ArrayCollection id="stateAC" source="{bloggersCol}"/> -->

<mx:Panel width="318" height="129" layout="absolute" title="Combo Box">
<mx:ComboBox x="10" y="10" width="278" id="cuisine" dataProvider="{bloggersCol}" >
</mx:ComboBox>
</mx:Panel>
</mx:Application>

/************************************************** ***
smakwam is offline   Reply With Quote
Old 02-14-2007, 01:11 PM   #2
xnegvx
Registered User
 
Join Date: Feb 2007
Posts: 4
Default

Hey ...

Though it has been a long time since you posted it, I am facing the same problem. I am trying to populate the combobox with records returned by the database which are parsed by php into xml format. I can not get the combobox populated. If you know what can be the issue can you please let me know...

Cheers,
Kartik
xnegvx is offline   Reply With Quote
Old 02-14-2007, 05:43 PM   #3
dr_zeus
Feathers
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999
Default

Check the documentation for the ComboBox's labelField property. When you give it an object, it doesn't know what property should be used for the label.
__________________
Josh Tynjala | Feathers
dr_zeus is offline   Reply With Quote
Old 02-16-2007, 09:12 PM   #4
Diavan
Registered User
 
Join Date: Feb 2007
Posts: 3
Thumbs up

// A literal XML string, returned by Webservice (e4x format), or created within the app.
var result:String = '<XMLList>
<Node name="foo" value="100"/>
<Node name="woo" value="200"/>
</XMLList>';

// Create an XML Object
var xmlObj:XML = new XML(result);

// Simply attach the above object to the Combobox dataprovider
cmbBox.dataProvider = xmlObj.Node;

// Above code should attach the XML tree with combo box.
// In order to display the 'name' in Combo box
cmbBox.labelField = "@name";
Diavan is offline   Reply With Quote
Old 02-18-2007, 11:39 AM   #5
xnegvx
Registered User
 
Join Date: Feb 2007
Posts: 4
Default

Thanks Guys... Documentation 101 about combobox helped a lot .. specially label field as mentioned in earlier posts. Now I am a happy flexer (for now) ..
xnegvx is offline   Reply With Quote
Old 02-25-2008, 04:25 PM   #6
tetito
Registered User
 
Join Date: Feb 2008
Posts: 2
Unhappy

Quote:
Originally Posted by Diavan View Post
// A literal XML string, returned by Webservice (e4x format), or created within the app.
var result:String = '<XMLList>
<Node name="foo" value="100"/>
<Node name="woo" value="200"/>
</XMLList>';

// Create an XML Object
var xmlObj:XML = new XML(result);

// Simply attach the above object to the Combobox dataprovider
cmbBox.dataProvider = xmlObj.Node;

// Above code should attach the XML tree with combo box.
// In order to display the 'name' in Combo box
cmbBox.labelField = "@name";


hey guys... I need show the field "value" of XML ... and show in a label... i cant doit i need your help...
how doit this action???
sorry, my english is bad!!!
tetito is offline   Reply With Quote
Old 02-25-2008, 07:02 PM   #7
tetito
Registered User
 
Join Date: Feb 2008
Posts: 2
Wink

Quote:
Originally Posted by Diavan View Post
// A literal XML string, returned by Webservice (e4x format), or created within the app.
var result:String = '<XMLList>
<Node name="foo" value="100"/>
<Node name="woo" value="200"/>
</XMLList>';

// Create an XML Object
var xmlObj:XML = new XML(result);

// Simply attach the above object to the Combobox dataprovider
cmbBox.dataProvider = xmlObj.Node;

// Above code should attach the XML tree with combo box.
// In order to display the 'name' in Combo box
cmbBox.labelField = "@name";
hey i do it !!!!
i change xml...


var result:String = '<XMLList>
<Node name="foo">
<value>"100"</value>
</Node>
<Node name="woo">
<value>"200"</value>
</Node>
</XMLList>';


for select value:

ComboBox(event.target).selectedItem.@indi


tetito is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox list rolls up again when try to scroll Flippie124 Components 1 10-06-2005 05:29 PM
Combobox label and the text in the list do not appear cheerful Components 0 08-10-2005 09:35 PM
List and ComboBox depth trouble stutterbug Components 2 07-10-2005 04:28 PM
rowHeight on list based components like ComboBox. I can't make it work. maglez Components 3 07-03-2005 03:20 AM
ComboBox skinning : controling the list style separately _marabout Components 1 12-09-2004 01:16 PM


All times are GMT. The time now is 06:45 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.