EDIT – Looks like you cannot parse data from PHP without going through XML. Using JSON will be the best way. Source
I’m very new to Flex been using it for 2.5 days. My Flex application accesses a PHP script that calculates two numbers. The script works as it is but I want to retrieve multiple variables from the PHP script so I can have an answer for not only addition but also multiplcation etc…
I hope I have made some sense….
Flex:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="Adding Numbers">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:HTTPService id="srvCalc" url="http://192.168.0.3/flex/flex-phpexample/calc.php"
resultFormat="text"
method="POST">
<s:request xmlns="">
<number1>{txtNumber1.text}</number1>
<number2>{txtNumber2.text}</number2>
</s:request>
</s:HTTPService>
</fx:Declarations>
<fx:Script>
<![CDATA[
private function btnCalc_Click(event:MouseEvent):void
{
srvCalc.send();
}
]]>
</fx:Script>
<s:VGroup width="400" horizontalCenter="0" verticalCenter="0">
<s:Label id="txtAnswer" text="{srvCalc.lastResult}" />
<s:Label text="First Number:" />
<s:TextInput id="txtNumber1"
width="100%"/>
<s:Label text="Second Number:"/>
<s:TextInput id="txtNumber2"
width="100%"/>
<s:Button id="btnCalc"
label="Calculate"
click="btnCalc_Click(event)"/>
</s:VGroup>
</s:View>
PHP:
<?php
$number1 = $_POST['number1'];
$number2 = $_POST['number2'];
print($number1 + $number2);
?>
The easiest method would be to have php return a JSON encoded block and then use http://flexjson.sourceforge.net/ to decode it in flex. There are some other methods you can use, but this is the easiest and most structured way.