1. Go to File > New > Flex Project.
2. In the dialog box, type helloWorld as the project name, and specify a project directory called helloWorld under the web root. Select Web application option as the application type, and then select an application server type of PHP.
3. Also give main source folder name
4. In the design view change value for layout as ‘vertical’.
5. Write following code in helloworld.mxml of code view.
<mx:HTTPService id="phpService"
url="http://localhost/helloWorld/helloWorld.php"
resultFormat="object" result="showResult()"/>
We can use an HTTPService component with any kind of server-side technology, including PHP pages.Here ,the service has an ID of phpService and a URL pointed to the helloWorld.php file, and the result format is generic object. The service is also set to call the showResult() function when it gets a result.
To actually use the service, its send method needs to be called.
For that we use <mx:Button> control .
<mx:Button label=”Call PHP” click=”phpService.send()”/>
Now, we need to create the showResult() function in an <mx:Script> block, below the <mx:HTTPService> tag.
<mx:Script>
<![CDATA[
import mx.controls.Alert;
privatefunction showResult():void {
Alert.show(phpService.lastResult as String,'Message from PHP');
}
]]>
</mx:Script>
The ActionScript code first declares an Import statement,which allows the application to use the Alert class from the mx.controls package. Secondly, it creates the showResult() function. This function displays an alert pop-up with the title "Message from PHP." The text within the alert box is the result from the HTTPService call to the helloWorld.php file.
6. Create a directory inside xampp/htdocs/ as helloWorld and a file helloworld.php inside that directory. The code is given below:
<?php
print "Hello world";
?>
7. Run the application to get the result as shown below.