THE ZEPINT NETWORK

programmer assist

Adobe Flex Adobe Flex XML Feeds

Adobe Flex Questions Adobe Flex Solutions Adobe Flex Articles

Adobe Flex delivers a standards-based programming methodology and runtime services for developing and deploying the presentation tier of applications that combine the richness of the desktop with the reach of the web: Rich Internet Applications.

The POST Solution for Flex, ActionScript & PHP

DiggBlinkRedditDeliciousTechnorati

article by Srirangan

This document hopes to provide a minimalist yet comprehensive solution on how to send user input from your Flex application to your backend PHP application. Of course the Hosting application here is based on PHP, but it should work for ASP, ASP.Net, Perl or any other Server Side platform.

Please Note: I am assuming you understand the basics of the programming.

The Architecture

[1] Client Side Form (Flex, Mxml)
[2] Client Side Form Submit Handler (Flex ActionScript)
- Data Binding
- Data POSTing
[3] Server Side Application (PHP)

Client Side Form

First we'll create a basic New User Registration Form on Flex. This can either be done via the Adobe Flex Builder Design mode or simply by entering the Mxml Source. For the sake of simplicity I'll provide the Mxml source for the form.


<mx:TitleWindow top="50" left="100" title="New User Registration Form">
<mx:Form>
<mx:FormItem name="email" label="Email Address">
<mx:TextInput id="email"/>
</mx:FormItem>
<mx:FormItem name="username" label="Desired Username">
<mx:TextInput id="username"/>
</mx:FormItem>
<mx:FormItem name="password" label="Password">
<mx:TextInput name="password" displayAsPassword="true"/>
</mx:FormItem>
<mx:FormItem name="confirm" label="Confirm Password">
<mx:TextInput id="password2" displayAsPassword="true"/>
</mx:FormItem>
<mx:FormItem name="sex" label="Sex">
<mx:ComboBox id="sex">
<mx:dataProvider>
<mx:Array>
<mx:String>Not Mentioned</mx:String>
<mx:String>Female</mx:String>
<mx:String>Male</mx:String>
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
</mx:FormItem>
<mx:FormItem name="buttons">
<mx:Button label="Submit" click="handleSubmit()"/>
</mx:FormItem>
</mx:Form>
</mx:TitleWindow>

Client Side Form Submit Handler

The method handleSubmit() will be invoked when the Submit button is clicked. handleSubmit binds the form input into an Object (postVars). Then an HTTPService object is created (signupService) who's destination Url is set to "signup.php". The request property of signupService is set to our postVars object, this ensures the variables are sent to signup.php. Most of the other properties being set are self-explanatory and don't warrant a comment.

public function handleSubmit():void
{
var postVars:Object = new Object;
postVars.email = email.text;
postVars.username = username.text;
postVars.password = password.text;
postVars.password2 = password2.text;
postVars.sex = sex.selectedItem;

var signupService:HTTPService = new HTTPService;
signupService.showBusyCursor = true;
signupService.concurrency = "last";
signupService.url = 'signup.php';
signupService.method = 'POST';
signupService.request = postVars;
signupService.resultFormat = 'text';
signupService.send();
signupService.addEventListener(ResultEvent.RESULT , signupServiceHandler );

function signupServiceHandler(e:ResultEvent):void
{
Alert.show(e.result.toString());
}
}

We are also adding an Result Event handle for signupService which will simply Alert the result of signup.php once the complete service-event cycle is complete.

Server Side Application (PHP)

Accessing these variables on PHP is similar to how you'd access any POST variable. Here's an example:

<?php
print_r($_POST);

echo $_POST['email'];
echo $_POST['username'];
echo $_POST['sex'];

if( $_POST['password'] != $_POST['password2'] )
{
echo 'Passwords dont match';
}
?>


If you have any questions, please feel free to ask them here: http://programmerassist.com/topic/30

Got a Adobe Flex Question?

Just Sign Up and ask the top Adobe Flex experts!

Search via Google

User Login

Email Address

Password

Adobe Flex Experts

Rank Expert Points
#1 Srirangan 1000
#2 Bejaan 500
This a list of the Top Adobe Flex experts, how many points do you have?

Leading Experts

Rank Expert Points
#1 frankzzsword 4650
#2 Bejaan 2950
#3 csfreak 1100
#4 Anurag 700
#5 keyvez 700
#6 nnarasimha 600
#7 Nakata 600
#8 martinig 600
#9 mastercomputers 550
#10 Abhishek Chatterjee 250
#11 Abels 250
#12 Huntress 150
#13 Adkron 150
#14 Yogesh 100
#15 lexxwern 100
This is a list of overall best performing experts, how many points do you have?