How to use URLVariables() in Flash AS3?
Using URLVariables in Flash or Flex we can send and receive data from server he is the example
This is the PHP Code nested in the server
Create a PHP file and place it in the server
<?php $email=$_POST['email']; $password=$_POST['password']; echo "email=".$_POST['email']."&password=".$password; ?>
Here is the code in Flash/Flex
//create URLRequest instace withe the target URL
var request:URLRequest = new URLRequest("http://www.example.com/data.php");
//create instance of the class
var variables:URLVariables = new URLVariables();
variables.email = druva.flash@gmail.com;
variables.password = 'dontexpectit';
//add the data to the URLRequest
request.data = variables;
//Choose a method as POST
request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
//Create EventListener
loader.addEventListener(Event.COMPLETE, handleComplete);
//send the request with URLLoader()
loader.load(request);
function handleComplete(event:Event) {
var loader:URLLoader = URLLoader(event.target);
var vars:URLVariables = new URLVariables(loader.data);
//Read data for the result
trace("vars.email: "+vars.email);
trace("vars.password: "+vars.password);
}