Highlighted

XML data retrieval for forms...

Avatar

Avatar

jjbaranowski

Avatar

jjbaranowski

jjbaranowski

07-10-2008

Greetings,



I'm trying to learn how to deal with XML in my flex
applications and I'm having some trouble. I created a simple flex
form and PHP file. The PHP queries a mySQL database and prints out
a line of text in XML format. Next I went into Flex builder 3 and
created the code shown below (from an example). The application
works, putting the data into the datagrid but I want to retieve the
data and use it in an action script function. This function could
possibly populate the text imput fields with the data from the SQL
table. Can someone help show me how to accomplish this taks?



<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute"

xmlns="*" creationComplete="send_data()">

<mx:Script>

<![CDATA[



private function send_data():void {

userRequest.send();



// This is where I want to do things with the returned XML
data. I dont need a datagrid.

username.text = (Here is where I want to use the XML fields)

}

]]>

</mx:Script>



<mx:Form x="22" y="10" width="493">

<mx:HBox>

<mx:Label text="Username"/>

<mx:TextInput id="username"/>

</mx:HBox>

<mx:HBox>

<mx:Label text="Email Address"/>

<mx:TextInput id="emailaddress"/>

</mx:HBox>

<mx:Button label="Submit" click="send_data()"/>

</mx:Form>

<mx:DataGrid id="dgUserRequest" x="22" y="128"
dataProvider="{userRequest.lastResult.users.user}">

<mx:columns>

<mx:DataGridColumn headerText="User ID"
dataField="userid"/>

<mx:DataGridColumn headerText="User Name"
dataField="username"/>

</mx:columns>

</mx:DataGrid>

<mx:TextInput x="22" y="292" id="selectedemailaddress"

text="{dgUserRequest.selectedItem.emailaddress}"/>

<mx:HTTPService id="userRequest" url="
http://www.hms-group.com/~jbaranowski/xml-engine.php"
useProxy="false" method="POST">

<mx:request xmlns="">

<username>{username.text}</username>

<emailaddress>{emailaddress.text}</emailaddress>

</mx:request>

</mx:HTTPService>

</mx:Application>