/ Published in: ActionScript 3
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'].
Expand |
Embed | Plain Text
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 ); }
Comments
Subscribe to comments
You need to login to post a comment.

Newbie AS3 question..
Can someone please explain how can I use this, In my AS3 project. and if I need like two other var included how to decliare those within the movieclip
when thying to compile the .swf I get compiler error...
Thanks, Nice peace of code, exactly what I was looking for..
Jackson
Hey jackson, hope this helps.
hi friend, do you know cheap ghd, cheap mbt shoes, christian louboutin shoes hot sell online recently?
we are china wholesaler company, offer good quality nike dunks, ghd mk4, cheap soccer jerseys online, cheap jerseys online enjoy much discount.cheap nike dunks,nike shox why are you hestitate, welcome for retail, dropship, and wholesale orders.
hey thanks.