package{ import flash.system.System; import flash.display.Sprite; import flash.events.Event; import flash.external.ExternalInterface; import flash.net.SharedObject; import flash.net.URLLoader; import flash.net.URLRequest; public class request extends Sprite{ private const SO_NAME:String = "helperSo"; private const SAVE_LOCAL:String = "saveLocal"; private const READ_LOCAL:String = "readLocal"; private const SEND_REQUEST:String = "sendRequest"; private const READY_CHECK:String ="readyCheck"; public function request(){ ExternalInterface.addCallback(SAVE_LOCAL, saveLocal); ExternalInterface.addCallback(READ_LOCAL, readLocal); ExternalInterface.addCallback(SEND_REQUEST, sendRequest); ExternalInterface.addCallback(READY_CHECK,readyCheck); } private function readyCheck():Boolean{ return true; } private function saveLocal(name:String, value:Object):void{ var so:SharedObject = SharedObject.getLocal(SO_NAME); so.data[name] = value; so.flush(); } private function readLocal(name:String):Object{ var so:SharedObject = SharedObject.getLocal(SO_NAME); return so.data[name]; } public function sendRequest(url:String, handlerName:String, method:String="GET", content:Object=null, headers:Object=null, cp:String="utf-8"):void{ if(cp=="gbk"){ System.useCodePage = true; }else{ System.useCodePage = false; } var loader:URLLoader = new URLLoader(); var request:URLRequest = new URLRequest(url); if(method){ request.method = method; } if (headers){ for each (var name:String in headers){ request.requestHeaders[name] = headers[name]; } } if (content){ request.data = content; } loader.addEventListener(Event.COMPLETE, function(e:Event):void{ ExternalInterface.call(handlerName, loader.data); }); loader.load(request); } } }