Reputation: 7316
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?
Upvotes: 0
Views: 2634
Reputation: 101
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)
Upvotes: 1
Reputation: 15717
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;
}
Upvotes: 6