Revision: 4573
Updated Code
at November 2, 2008 23:20 by chrisaiv
Updated Code
var bg_mc:MovieClip = new MovieClip(); bg_mc.graphics.beginFill(0xFF0000, 1); bg_mc.graphics.drawRect(0, 0, 100, 100); bg_mc.graphics.endFill(); bg_mc.x = stage.stageWidth / 2 - bg_mc.width / 2; bg_mc.y = stage.stageHeight / 2 - bg_mc.height / 2 ; bg_mc.buttonMode = true; bg_mc.addEventListener(MouseEvent.MOUSE_DOWN, visitSite); addChild(bg_mc); function visitSite(e:MouseEvent):void { var url:String = "http://api.flickr.com/services/rest/"; var request:URLRequest = new URLRequest(url); var requestVars:URLVariables = new URLVariables(); requestVars.api_key = "3c84c0ca7f9ae17842a370a3fbc90b63"; requestVars.method = "flickr.test.echo"; requestVars.format = "rest"; requestVars.foo = "bar"; requestVars.sessionTime = new Date().getTime(); request.data = requestVars; request.method = URLRequestMethod.POST; var urlLoader:URLLoader = new URLLoader(); urlLoader = new URLLoader(); urlLoader.dataFormat = URLLoaderDataFormat.TEXT; urlLoader.addEventListener(Event.COMPLETE, loaderCompleteHandler, false, 0, true); urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler, false, 0, true); urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, false, 0, true); urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true); for (var prop:String in requestVars) { //trace("Sent: " + prop + " is: " + requestVars[prop]); } try { urlLoader.load(request); } catch (e:Error) { trace(e); } } function loaderCompleteHandler(e:Event):void { var responseVars = URLVariables( e.target.data ); trace( "responseVars: " + responseVars ); } function httpStatusHandler( e:HTTPStatusEvent ):void { //trace("httpStatusHandler:" + e); } function securityErrorHandler( e:SecurityErrorEvent ):void { trace("securityErrorHandler:" + e); } function ioErrorHandler( e:IOErrorEvent ):void { //trace("ORNLoader:ioErrorHandler: " + e); dispatchEvent( e ); }
Revision: 4572
Updated Code
at February 11, 2008 17:39 by chrisaiv
Updated Code
var bg_mc:MovieClip = new MovieClip(); bg_mc.width = 320; bg_mc.height = 240; bg_mc.x = 0; bg_mc.y = 0; bg_mc.buttonMode = true; bg_mc.addEventListener(MouseEvent.MOUSE_DOWN, visitSite); addChild(mc); function visitSite(e:MouseEvent):void { var url:String = "http://www.google.com"; var request:URLRequest = new URLRequest(url); var variables:URLVariables = new URLVariables(); variables.sessionTime = new Date().getTime(); variables.sessionUser = "guest"; request.data = variables; request.method = URLRequestMethod.POST; try { navigateToURL(request, "_self"); } catch (e:Error) { trace(e); } }
Revision: 4571
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 10, 2008 14:42 by chrisaiv
Initial Code
var bg_mc:MovieClip = new MovieClip(); bg_mc.width = 320; bg_mc.height = 240; bg_mc.x = 0; bg_mc.y = 0; bg_mc.buttonMode = true; bg_mc.addEventListener(MouseEvent.MOUSE_DOWN, visitSite); addChild(mc); function visitSite(e:MouseEvent):void { var url:String = "http://www.google.com"; var request:URLRequest = new URLRequest(url); var variables:URLVariables = new URLVariables(); variables.sessionTime = new Date().getTime(); variables.sessionUser = "guest"; request.data = variables; request.method = URLRequestMethod.POST; try { navigateToURL(request, "_self"); } catch (e:Error) { trace(e); } }
Initial URL
Initial Description
This function also shows how to pass variables to a REST service. This could also be used to pass vars that PHP can later collect as $_POST['params'].
Initial Title
AS3: Sending Data using POST
Initial Tags
Initial Language
ActionScript 3