ActionScript 3 PHP加载器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 PHP加载器相关的知识,希望对你有一定的参考价值。

//Usage
var myPhpLoader = new phpLoader("myPhpFile.php", ["val1", "Value"], ["val2", "Value"]);				
myPhpLoader.addEventListener("loaded", function(e:Event) { 
	trace(e.target.loader.data["a"]); 
} );

//CODE
package  
{
	import flash.display.Loader;
	import flash.net.URLVariables;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.events.Event;
	
	public class phpLoader extends Loader
	{
		public var loader:URLLoader = new URLLoader();		
		
		public function phpLoader(url:String, ...args) 
		{			
			loader.addEventListener(Event.COMPLETE, Loaded);
			var request:URLRequest = new URLRequest(url);
			
			if(args.length>0){
				var variables:URLVariables = new URLVariables();
				for (var i:int = 0; i < args.length; i++) {
					variables[args[i][0]] = args[i][1];				
				}				
				request.method = URLRequestMethod.POST;
				request.data = variables;				
				loader.dataFormat = URLLoaderDataFormat.VARIABLES;
			}			
			 
			try{
				loader.load(request);
			}
			catch (error:Error) {
				trace("Unable to load URL");
				dispatchEvent(new Event("error", true));				
			}
			
			function Loaded (event:Event):void {
				trace( loader.data );			
				dispatchEvent(new Event("loaded", true));				
			}	
		}
		
	}
}

//myPhpFile.php
<?PHP
	$val1= $_POST['val1'];
	$val2= $_POST['val2'];
	//... do something with these values.
	echo 'a=';
	echo $val1+$val2;
?>

以上是关于ActionScript 3 PHP加载器的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 带缓存的简单加载管理器

ActionScript 3 基本的外部XML加载器

ActionScript 3 加载器上下文

ActionScript 3 AS3预加载器

ActionScript 3 xml加载器类

ActionScript 3 AS3:预加载器