Share on Twitter (with Bit.ly shortned link) [FLEX]


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //Twitter/Bit.Ly Share Imports
  2. import flash.net.navigateToURL;
  3. import mx.rpc.events.ResultEvent;
  4. import mx.rpc.xml.SimpleXMLDecoder;
  5. import mx.utils.ObjectUtil;
  6.  
  7.  
  8. //Twitter/Bit.Ly Share Vars
  9. private var bitLyLoader:URLLoader;
  10.  
  11.  
  12. /*
  13.  * Call this function to share on twitter, passing your url trough bit.ly!
  14. */
  15. private function twitterShare(articleUrl:String):void
  16. {
  17. // Insert your bit.ly account name & API Key bellow
  18. var bitLyApiUrl:String = "http://api.bit.ly/v3/shorten?login=ACCOUNT NAME&apiKey=API KEY&longUrl="+articleUrl+"&format=xml";
  19. var bitLyApi:URLRequest = new URLRequest(bitLyApiUrl);
  20. bitLyLoader = new URLLoader(bitLyApi);
  21. bitLyLoader.addEventListener(Event.COMPLETE, bitLyFinished);
  22. }
  23.  
  24. /*
  25. * Get the short link & post to twitter
  26. */
  27. private function bitLyFinished(event:Event):void
  28. {
  29. // Lets decode the bit.ly answer!
  30. var getLink:XMLDocument = new XMLDocument(bitLyLoader.data);
  31. var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
  32. var bitLyLink:Object = decoder.decodeXML(getLink);
  33. // Insert your message bellow! Use %23 for trending topics! (Example: %23DigitalWorks)
  34. var URL:String = "http://twitter.com/home?status=Currently reading "+bitLyLink+" %23DigitalWorks";
  35. navigateToURL(new URLRequest(URL), '_blank');
  36. }

URL: http://www.digitalwks.com/blogs/diogo-raminhos

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.