<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer 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="100%" height="100%" backgroundAlpha="0">
<s:layout>
<s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>
</s:layout>
<fx:Declarations>
<s:HTTPService id="hsData" method="GET"
url="http://code.immanuelnoel.com/Services/HelloWorld.php?getData=1"
result="hsData_resultHandler(event)"
fault="hsData_faultHandler(event)"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
/** Call the REST Webservice on clicking the 'Get Data' button
*/
protected function btGetData_clickHandler(event:MouseEvent):void
{
cursorManager.setBusyCursor();
hsData.send();
}
/** Event Listener for handling the result obtained from the Webservice
*/
protected function hsData_resultHandler(event:ResultEvent):void
{
displayPopUp(String(event.result.data.testData));
}
/** Event Listener for handling errors while calling the Webservice
*/
protected function hsData_faultHandler(event:FaultEvent):void
{
displayPopUp("Oops! Connectivity Error");
}
/** Displaying a PopUp, and updating the label in the PopUp
* with the data fetched from the Webservice
*/
private function displayPopUp(data:String):void
{
var popup:Example3_PopUp = PopUpManager.createPopUp(this, Example3_PopUp, true) as Example3_PopUp;
PopUpManager.centerPopUp(popup);
popup.lDisplay.text = data;
cursorManager.removeAllCursors();
}
]]>
</fx:Script>
<s:Label id="lDisplay" text="Demonstrates connecting to a PHP based REST webservice" color="#FFFFFF" fontFamily="Verdana" fontSize="14"/>
<s:Button id="btGetData" label="Click Me !" click="btGetData_clickHandler(event)"/>
</s:BorderContainer>