Posted By

arpit on 12/19/09


Tagged

api


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

alejandromb
ginoplusio
StrawMan
goliatone


Shorten URLs with Bitly


 / Published in: ActionScript 3
 

  1. var pattern:RegExp = /(http[s]?:\/\/[\S]+)\s/ig;
  2. txt.addEventListener(Event.CHANGE, function(event:Event):void{
  3. var results:Array = txt.text.match(pattern);
  4. if(results.length > 0) {
  5. for(var i:int=0; i< results.length; i++){
  6. if(results[i].indexOf("bit.ly")==-1){
  7. shortenURL(results[i], handler)
  8. }
  9. }
  10. }
  11.  
  12. private function shortedURL(url:String , handler:Function):void{
  13. var bitlyURL:String = "http://api.bit.ly/shorten?version=2.0.1&format=xml&longUrl="+escape(url)+"&login="+LOGIN+"&apiKey="+API_KEY;
  14.  
  15. var urlLoader:URLLoader = new URLLoader();
  16. var req:URLRequest = new URLRequest(bitlyURL);
  17. statusLabel.text = "Shortening ..."
  18. urlLoader.addEventListener(Event.COMPLETE, function(event:Event):void{
  19. try{
  20. var shortURL:String = XML(event.target.data).results.nodeKeyVal.shortUrl;
  21.  
  22. }catch(e:Error){}
  23. });
  24. urlLoader.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void{
  25.  
  26. });
  27. urlLoader.load(req);
  28. }

Report this snippet  

You need to login to post a comment.