Search code examples
actionscript-3objectreference-type

How to check whether an AS3 "Object" variable is completely empty?


In Actionscript 3.0, how do I check if var myObject:Object is functionally identical to {}?

I take it I can't do ...

if (myObject == {}) {
  // etc
}

... because Objects are reference types, right?


Solution

  • Check that it exists at least one field :

    function isEmptyObject(myObject:Object):Boolean {
     var isEmpty:Boolean=true;
    
     for (var s:String in myObject) {
       isEmpty = false;
       break;
     }
    
     return isEmpty;
    }