/ Published in: ActionScript 3
I needed a way to do a Database lookup using GET. This simple example sends a GET requests and shows how to collect a response that would look like this "success=true&path=xyz.flv"
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var requestVars:URLVariables = new URLVariables(); requestVars.object_name = "key1"; requestVars.cache = new Date().getTime(); var request:URLRequest = new URLRequest(); request.url = "http://localhost:3000/videos/find_path/"; request.method = URLRequestMethod.GET; request.data = requestVars; for (var prop:String in requestVars) { trace("Sent " + prop + " as: " + requestVars[prop]); } var loader:URLLoader = new URLLoader(); loader.dataFormat = URLLoaderDataFormat.TEXT; loader.addEventListener(Event.COMPLETE, loaderCompleteHandler); loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); try { loader.load(request); } catch (error:Error) { trace("Unable to load URL"); } function loaderCompleteHandler(e:Event):void { var variables:URLVariables = new URLVariables( e.target.data ); if(variables.success) { trace(variables.path); } } function httpStatusHandler (e:Event):void { //trace("httpStatusHandler:" + e); } function securityErrorHandler (e:Event):void { trace("securityErrorHandler:" + e); } function ioErrorHandler(e:Event):void { trace("ioErrorHandler: " + e); }