3 Replies Latest reply on Sep 14, 2010 12:16 PM by Gregory Lafrance

    Printing contents of a SharedObject (no matter what is contains)

    Gregory Lafrance Level 6

      I'm taking a close look at the ESRIA Dashboard application, and when I tried to create a method to trace the contents of its SharedObject, and the actual method called recursively to build up a string representing the SO contents, it ends up being really complex, because you never know if anything you are currently looking at is an Object, an "int" class type, or just nothing.

       

      So is there an easier way to do this than what I have here? Thanks in advance.

       

      private function showState():void{
       var stateString:String = "";
       var sharedObjectData:Object = StateManager.getSO().data;
       stateString = objectContents(sharedObjectData, 0);
       trace(stateString);     
      }
      private function objectContents(obj:Object, indentLevel:int):String{
       var retStr:String ="";
       var indent:String = "";
       for(var i:uint=0;i<indentLevel;i++){
        indent+="\t";
       }     
       for(var key:String in obj){
        retStr += indent + key + "\n";
        if(obj[key] is Object && obj[key] != ""){
         if(Class(getDefinitionByName(getQualifiedClassName(obj[key]))).toString() == "[class int]"){
          retStr += indent + "\t" + obj[key] + "\n";              
         }else{
          retStr += objectContents(obj[key], indentLevel+1);                         
         }
        }else if(obj[key] == null){
         retStr += indent + indent + "none\n";
        }else if(obj[key] is Object && obj[key] == ""){
         if(obj[key] == "0"){
          retStr += indent + "\t" + obj[key] + "\n";                         
         }else{
          retStr += indent + indent + "none\n";
         }
        }else{
         retStr += indent + obj[key];
        }
       }
       return retStr;
      }