aaaidan
aaaidan

Reputation: 7316

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?

Upvotes: 0

Views: 2634

Answers (2)

Giorgio Natili
Giorgio Natili

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

Patrick
Patrick

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

Related Questions