Load media, datas file, or variables

Load variables from a PHP script

This time we'll load variables from a PHP script and no more from a text file.

package;
import flash.Lib; 
import flash.net.URLRequest; 
import flash.events.Event; 
import flash.net.URLLoader; 
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
      class Main
      {
      		public var loader:Loader;
      		public var data_loader:URLLoader;
      		static function main()
      		{
      			new Main();
      		}
      		public function new()
      		{      	 
      			exemple5();
      		} 
      		public function exemple5()
      		{
      		    var loader = new URLLoader();  
      		    var request = new URLRequest('script2.php');
      		    request.method = URLRequestMethod.GET;
      		    
      		    loader.addEventListener(Event.COMPLETE, loadingIsOver);
      		    loader.load(requeste);
      		}
      		public function loadingIsOver(e:Event)
      		{
      		    var variables = new URLVariables(e.currentTarget.data);
      		    trace(variables.myVar1+" "+variables.myVar2);
      		}
      		 
	}  

We use URLRequestMethod class in order to define the POST and GET method.

We are going to catch variables with GET method.

We're going to use a PHP script which will be transmit variables with GET method.

The PHP script :

<?php
/* Do whatever you want ..
* ...
*/

echo "myVar1=Hello&myVar2=World";
?>

We add an event listener (COMPLETE event ) and the function loadingIsOver() will be executed at the end of the loading. Usenew URLVariables to parse the string that we've loaded.

Result :

output

Alternative content

Get Adobe Flash player

(97 times)