Browsing Posts in Adobe Flex

Get data from php in flex

No comments


First the data in PHP looks like this–

echo “<CALCU>”;

echo “<CALCUS>”;
echo “<ID>”1232″</ID>”;
echo “<AMTSPE>”12365″</AMTSPE>”;
echo “<DATE>”2007/11/11″</DATE>”;
echo “<DESCRY>”hai”</DESCRY>”;
echo “</CALCUS>”; .

echo “</CALCU>”;

Now to get this data into Flex app we got to use HttpService(there are other services) and a property result in it..

<mx:HTTPService id=”srvMain” useProxy=”false” showBusyCursor=”true”
fault=”httperror()” result=”readmeMain(event);”/>

now the result will be fetched into event so to get it define the method as mentioned in the result property of the httpService.. as below..

private function readmeMain(event:ResultEvent):void
{
var amountspe:String=new String;

amountspe=event.result.CALCU.CALCUS.AMTSPE;

}

Now the string amountspe contains the valuse sent by the PHP page(particular as given in colors).

Similarly get other values into strings or inputs..

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="30" horizontalScrollPolicy="off" verticalScrollPolicy="off" backgroundColor="#000000" backgroundGradientAlphas="{[0,0]}">
<mx:Script>
<![CDATA[
import flash.net.URLRequest;
//private var contentFrame:
private var myArr:Array = new Array("home","bio","contact");

]]>
</mx:Script>
<mx:ButtonBar width="100%" height="100%" dataProvider="{myArr}" itemClick="navigateToURL(new
URLRequest(event.label+'.html'),'contentFrame');" color="#ffffff"/>
<mx:Label id="test" y ="150" /></mx:Application>

Here’s an example (you can view page source to see the HTML):

A few notes:

In AS3:

The frame name must by exactly the same (of course! – but this came up in the forums), and must be a string, passed as a parameter in navigateToURL (in place of “_blank” etc)

In AS2: (Flash): The parameter is ’supposed’ to be a string here as well, but I could only get it to work with out the quotes (as a var) – here you use the getURL() method.

Note: if using relative urls, it will appear not to work while developing, but should once you get it on the server – flash security. This seems o only be the case with as3

Cheers,