/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package { import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.net.navigateToURL; import flash.net.URLLoader; import flash.net.URLRequest; import flash.net.URLLoaderDataFormat; public class Main extends Sprite { private var tinyLoader:URLLoader public function Main():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); stage.addEventListener(MouseEvent.CLICK, postToTwitter); tinyLoader = new URLLoader(); tinyLoader.dataFormat = URLLoaderDataFormat.TEXT; tinyLoader.addEventListener(Event.COMPLETE, gotTinyURL); } private function postToTwitter(event:MouseEvent):void { trace("postToTwitter()"); tinyLoader.load(new URLRequest('http://tinyurl.com/api-create.php?url=http://www.adrianparr.com')); } private function gotTinyURL(event:Event):void { trace(tinyLoader.data); var reqString:String = 'http://twitter.com/home?status=Check this out ' + encodeURIComponent(tinyLoader.data); navigateToURL(new URLRequest(reqString), "_blank"); } } }
URL: http://www.nayansavla.com/blog/?p=253