Posted By

adrianparr on 07/20/11


Tagged

post twitter as3 URLLoader URLRequest tinyurl navigateToURL


Versions (?)

AS3 Post tinyurl to Twitter via Twitter webpage


 / Published in: ActionScript 3
 

URL: http://www.nayansavla.com/blog/?p=253

  1. package
  2. {
  3. import flash.display.Sprite;
  4. import flash.events.Event;
  5. import flash.events.MouseEvent;
  6. import flash.net.navigateToURL;
  7. import flash.net.URLLoader;
  8. import flash.net.URLRequest;
  9. import flash.net.URLLoaderDataFormat;
  10.  
  11. public class Main extends Sprite
  12. {
  13. private var tinyLoader:URLLoader
  14.  
  15. public function Main():void
  16. {
  17. if (stage) init();
  18. else addEventListener(Event.ADDED_TO_STAGE, init);
  19. }
  20.  
  21. private function init(e:Event = null):void
  22. {
  23. removeEventListener(Event.ADDED_TO_STAGE, init);
  24. stage.addEventListener(MouseEvent.CLICK, postToTwitter);
  25. tinyLoader = new URLLoader();
  26. tinyLoader.dataFormat = URLLoaderDataFormat.TEXT;
  27. tinyLoader.addEventListener(Event.COMPLETE, gotTinyURL);
  28. }
  29.  
  30. private function postToTwitter(event:MouseEvent):void {
  31. trace("postToTwitter()");
  32. tinyLoader.load(new URLRequest('http://tinyurl.com/api-create.php?url=http://www.adrianparr.com'));
  33. }
  34.  
  35. private function gotTinyURL(event:Event):void {
  36. trace(tinyLoader.data);
  37. var reqString:String = 'http://twitter.com/home?status=Check this out ' + encodeURIComponent(tinyLoader.data);
  38. navigateToURL(new URLRequest(reqString), "_blank");
  39. }
  40.  
  41. }
  42.  
  43. }

Report this snippet  

You need to login to post a comment.