Flex/PHP/XML data issue
Posted
by reado
on Stack Overflow
See other posts from Stack Overflow
or by reado
Published on 2010-04-08T15:29:25Z
Indexed on
2010/04/08
15:43 UTC
Read the original article
Hit count: 372
I have built a simple application in Flex. When the application loads, a GET request is made to the xmlService.php file with parameters "fetchData=letters". This tells the PHP to return the XML code.
In Flex Debug I can see the XML data being sent by the PHP to the flex client.
What I need it to do is populate the first drop down box (id="letter") with this data, however nothing is being received by Flex. I added an Alert.show() to check what was being returned but when the application runs, the alert is blank.
Can anyone help? Thanks in advance.
Image: http://static.readescdn.com/misc/flex.gif
// Flex
<?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="300" height="300"
creationComplete="windowedapplication1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import spark.events.IndexChangeEvent;
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
var params:Object = {'fetchData':'letters'};
xmlService.send(params);
}
protected function xmlService_resultHandler(event:ResultEvent):void
{
var id:String = xmlService.lastResult.data.id.value;
//Alert.show(xmlService.lastResult.data.id.value);
if(id == 'letter')
{
letter.dataProvider = xmlService.lastResult.data.letter;
letter.enabled = true;
}
else
if(id == 'number')
{
number.dataProvider = xmlService.lastResult.data.number;
number.enabled = true;
submit.enabled = true;
}
else
{
submit.label = 'No Data!';
}
}
protected function xmlService_faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.message);
}
protected function letter_changeHandler(event:IndexChangeEvent):void
{
var params:Object = {'fetchData':'numbers'};
xmlService.send(params);
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="xmlService"
url="URL_GOES_HERE"
method="POST"
useProxy="false"
resultFormat="e4x"
result="xmlService_resultHandler(event)"
fault="xmlService_faultHandler(event)"/>
</fx:Declarations>
<s:DropDownList x="94" y="10" id="letter" enabled="false" change="letter_changeHandler(event)" labelField="value"></s:DropDownList>
<s:DropDownList x="94" y="39" id="number" enabled="false" labelField="value"></s:DropDownList>
<s:Button x="115" y="68" label="Submit" id="submit" enabled="false"/>
</s:WindowedApplication>
// PHP
<?
if(isset($_POST['fetchData']))
{
if($_POST['fetchData'] == 'letters')
{
$xml = '<data>
<id value="letters"/>
<letter label="Letter A" value="a"/>
<letter label="Letter B" value="b"/>
<letter label="Letter C" value="c"/>
</data>';
}
else
if($_POST['fetchData'] == 'numbers')
{
$xml = '<data>
<id value="letters"/>
<number label="Number 1" value="1"/>
<number label="Number 2" value="2"/>
<number label="Number 3" value="3"/>
</data>';
}
else
{
$xml = '<data>
<result value="'.$_POST['fetchData'].'"/>
</data>';
}
echo $xml;
}
else
{
echo '<data>
<result value="NULL"/>
</data>';
}
?>
© Stack Overflow or respective owner