Return to Snippet

Revision: 21746
at January 2, 2010 15:23 by arpit


Updated Code
var pattern:RegExp = /(http[s]?:\/\/[\S]+)\s/ig;
txt.addEventListener(Event.CHANGE, function(event:Event):void{
     var results:Array = txt.text.match(pattern);
     if(results.length > 0) {
        for(var i:int=0; i< results.length; i++){
          if(results[i].indexOf("bit.ly")==-1){
          shortenURL(results[i], handler)
        }
     }
}

private function shortedURL(url:String , handler:Function):void{
   var bitlyURL:String = "http://api.bit.ly/shorten?version=2.0.1&format=xml&longUrl="+escape(url)+"&login="+LOGIN+"&apiKey="+API_KEY;
   
   var urlLoader:URLLoader = new URLLoader();
   var req:URLRequest = new URLRequest(bitlyURL);
   statusLabel.text = "Shortening ..."
   urlLoader.addEventListener(Event.COMPLETE, function(event:Event):void{
      try{
	 var shortURL:String = XML(event.target.data).results.nodeKeyVal.shortUrl;
	
       }catch(e:Error){}
   });
   urlLoader.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void{
				
   });
   urlLoader.load(req);
}

Revision: 21745
at December 19, 2009 21:22 by arpit


Initial Code
var pattern:RegExp = /(http[s]?:\/\/[\S]+)\s/ig;
txt.addEventListener(Event.CHANGE, function(event:Event):void{
     var results:Array = txt.text.match(pattern);
     if(results.length > 0) {
        for(var i:int=0; i< results.length; i++){
          if(results[i].indexOf("bit.ly")==-1){
          shortenURL(results[i], handler)
        }
     }
}

private function shortedURL(url:String , handler:Function):void{
   var apiKey:String = API_KEY;
   var bitlyURL:String = "http://api.bit.ly/shorten?version=2.0.1&format=xml&longUrl="+escape(url)+"&login=espressoreader&apiKey="+apiKey;
   
   var urlLoader:URLLoader = new URLLoader();
   var req:URLRequest = new URLRequest(bitlyURL);
   statusLabel.text = "Shortening ..."
   urlLoader.addEventListener(Event.COMPLETE, function(event:Event):void{
      try{
	 var shortURL:String = XML(event.target.data).results.nodeKeyVal.shortUrl;
	
       }catch(e:Error){}
   });
   urlLoader.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void{
				
   });
   urlLoader.load(req);
}

Initial URL

                                

Initial Description

                                

Initial Title
Shorten URLs with Bitly

Initial Tags
api

Initial Language
ActionScript 3