Passing and Receving PHP Variables - Flex3

The following article covers the particular topic of passing and receiving php variables within Flex 3 using both MXML and AS3 (Actionscript 3.0). Not many articles out their clearly explain this particular topic with clarity; therefore ive taken the liberty of explaining the code involved and including sample files that everyone can use to easily create dynamic web apps.

Please be aware that basic knowledge of mxml and as3 is needed in order to understand what is going on. Also keep in mind that you need a "local" or live webserver in order to test this application. I will be covering such topics in the future and hope that you enjoy this tutorial, my very first!! YAY!

CREATING THE RESULT FUNCTION


		<![CDATA[
			import mx.rpc.events.ResultEvent;
			import mx.controls.Alert;
			
			//ResultEvent for HTTPService
			private function LoginResult(e:ResultEvent):void{
				Alert.show(e.result.email as String, 'Message From PHP');
			}
		]]>

CREATING THE HTTPSERVICE

	<!--
		httpservice used to communicate with php
		*make sure the resultformat is in flashvars
		*make sure the variables in php receive the POST not GET
		*the location of the php file is essential, let it be
			the absolute path to the php file called.
	-->
	
		<!-- variables in php that will receive information -->
		
			
				<!-- retrieve the text input of the email formitem below -->
				{email.text}
			
			
	

CREATING THE FORM

	<!-- canvas used to hold from -->
	
		<!-- form for text input -->
		
			
			
			    
			
			
			    
			
		
		<!-- activate the httpservice when clicked -->
		
	

NOW FOR SOME PHP

<?php 
	//email variable must receive the same exact variable in flash
	//this means that casing is sensitive and must be exact
	/*
		ex.
		FLASH:
			Variable : username
		PHP:
			$_POST['username']
	*/
	$email = $_POST['email'];

	//must echo out a query type string for flash to parse variables
	echo "email=$email";
?>

And thats all you need! I hope to write more in the future as to how to retrieve data from the backend and use the information you get to display awesomness to the user. Let me know what you think!

Comments

images?

Hey your example is great. but what i want to do is use php to read images from a folder then display in flex 3 tilelist. Can you help me?