home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Beez.swf / scripts / mx / utils / NameUtil.as
Encoding:
Text File  |  2008-09-03  |  1.8 KB  |  71 lines

  1. package mx.utils
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.utils.getQualifiedClassName;
  5.    import mx.core.IRepeaterClient;
  6.    import mx.core.mx_internal;
  7.    
  8.    use namespace mx_internal;
  9.    
  10.    public class NameUtil
  11.    {
  12.       
  13.       mx_internal static const VERSION:String = "3.0.0.0";
  14.       
  15.       private static var counter:int = 0;
  16.        
  17.       
  18.       public function NameUtil()
  19.       {
  20.          super();
  21.       }
  22.       
  23.       public static function displayObjectToString(displayObject:DisplayObject) : String
  24.       {
  25.          var result:String = null;
  26.          var s:String = null;
  27.          var indices:Array = null;
  28.          var o:DisplayObject = displayObject;
  29.          while(o != null)
  30.          {
  31.             if(o.parent && o.stage && o.parent == o.stage)
  32.             {
  33.                break;
  34.             }
  35.             s = o.name;
  36.             if(o is IRepeaterClient)
  37.             {
  38.                indices = IRepeaterClient(o).instanceIndices;
  39.                if(indices)
  40.                {
  41.                   s += "[" + indices.join("][") + "]";
  42.                }
  43.             }
  44.             result = result == null ? s : s + "." + result;
  45.             o = o.parent;
  46.          }
  47.          return result;
  48.       }
  49.       
  50.       public static function createUniqueName(object:Object) : String
  51.       {
  52.          if(!object)
  53.          {
  54.             return null;
  55.          }
  56.          var name:* = getQualifiedClassName(object);
  57.          var index:int = name.indexOf("::");
  58.          if(index != -1)
  59.          {
  60.             name = name.substr(index + 2);
  61.          }
  62.          var charCode:int = name.charCodeAt(name.length - 1);
  63.          if(charCode >= 48 && charCode <= 57)
  64.          {
  65.             name += "_";
  66.          }
  67.          return name + counter++;
  68.       }
  69.    }
  70. }
  71.