sample code which guide you on how to communicate between Flex and Php

This article is writing for a Flex newbie like me. :) , guides a Flex newbie on how to communicate between Flex and Php.There are different ways of connecting Web clients written in Flex with the server-side applications being that Java, PHP, Ruby on Rails, ASP or anything else that can generate HTTP responses(Having a secured php web hosting service is also important) Using HTTPService MXML tag,it can communicate with your server application.The below is the sample code,built with Flex 2 SDK.

Step1: create flex.php

   $jouemail = "null";
   $joupassword = "null";
   if (isset($_POST['jouemail']) && isset($_POST['joupassword'])){
     $jouemail = $_POST['jouemail'];
     $joupassword = $_POST['joupassword'];

   $Return = "<login>";
   $Return .= $jouemail;
   $Return .= "</login>";  

   print $Return;

Step2: create login.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>the sample that communicate between Flex and Php-login</title>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=,0,19,0 width="500" height="375" title="flex">
<param name="movie" value="login.swf" />
<param name="quality" value="high" />
<embed src="login.swf" quality="high" pluginspage= type="application/x-shockwave-flash" width="500" height="375"></embed>

Step3: create login.swf/login.mxml,put 3 file at the same folder

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute" width="500" height="300">
import mx.controls.ProgressBar;
import mx.charts.chartClasses.DualStyleObject;
import mx.collections.XMLListCollection;
import mx.collections.ArrayCollection;
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
import mx.containers.ApplicationControlBar;
import mx.controls.ToolTip;
import mx.controls.Alert;  

private var loginResult : String;  

public function getLoginResult(event : ResultEvent) : void{
  loginResult = event.result.login;, "result");
  <mx:HTTPService id="userLogin" url="flex.php" useProxy="false" method="POST" result="getLoginResult(event)">
       <mx:request xmlns="">

  <mx:Form label="login" x="108" y="70">
   <mx:FormItem label="Email:">
     <mx:TextInput id="jouemail"/>
      <mx:FormItem label="Password:">
           <mx:TextInput id="joupassword" displayAsPassword="true"/>
        <mx:Button label="login" click="userLogin.send();"/>
Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

2 Responses to “sample code which guide you on how to communicate between Flex and Php”

  1. judy says:

    Thanks so very much for taking your time to create this very useful and informative site. I have learned a lot from your site. Thanks!!r

  2. ppmohapatra says:

    hi I found it to be a very useful sample code.
    but, since in login.mxml, components other than ResultEvent and Alert are not used I want to comment out other import statements.

    Can anybody tell me what is the line comment notation or block comment notation!

    There are couple of other doubts also.
    viz. what is the advantage of having login.swf object embedded inside login.php (we can directly use login.swf as url)!! what technology is used for the 3 boxes in this page where the sample code is mentioned!!!

Leave a Reply