/ Published in: ActionScript 3
base 58 encoding in AS3 used to create a short url for flickr (flic.kr/p/) from a photo id. Function requires the flickr photo id to be passed in cast as a Number. Example below
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* Function used to return flickr short url from a photo id. example of usage var shortFlickrURL:String = 'www.flic.kr/p/' + Base58Encoder.encode(Number('4725679319') ); /// returns www.flic.kr/p/8cAkPD /// short url for this full url http://www.flickr.com/photos/ninjaparade/4725679319/ */ package { /** * @author ninjaparade */ public class Base58Encoder { public static function encode( num : Number ) : String { var alphabet : String = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' ; var base_count : int = alphabet.length; var encode : String = ""; while(num >= base_count) { var div : int = num / base_count; var mod : int = (num - base_count * Math.round(div) ); encode = alphabet.charAt(mod) + encode; num = Math.round(div); } if(num) { encode = alphabet.charAt(num) + encode; } return encode; } } }