Question

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?

Was it helpful?

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;
}

OTHER TIPS

This works with dynamic object and classes, to check if an object contains fields this should be a more general solution

import flash.utils.describeType;

var test:String = "test";

var data:XML = describeType(test);
trace(data..accessor.length() > 0 || data..variable.length() > 0)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top