topical media & game development

talk show tell print

professional-flex-code-09-ReverseFormatter.ax

professional-flex-code-09-ReverseFormatter.ax [swf] flex


  package 
  {
    import mx.formatters.Formatter
    // Custom formatters must extend mx.formatters.Formatter
    public class @ax-professional-flex-code-09-ReverseFormatter extends Formatter {
          
      public function @ax-professional-flex-code-09-ReverseFormatter() {
        super();
      }
      // Custom formatters must extend override format().
      override public function format(formatObj:Object):String         {
        if(formatObj.length == 0) {    
          // return empty string and set error property if string has zero length.
          error="Can not format an empty String";
          return ""
        } else {
                error=null;
          var returnString:String = "";
          // loop through value and build string in reverse
          for(var i:Number=formatObj.length; i>=0; i--){
            returnString = returnString + formatObj.charAt(i);
          }
          return returnString;
        }
      }
    }
  }
  
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.