“in” Operator

var obj:Object = {name: "Joe", hobby: "Guitar", age:"80"};

if ("name" in obj){
	trace(obj, " has a name property");
}

if ("x" in obj == false){
	trace(obj, " doesn't have an x property");
}


var mySprite:Sprite = new Sprite();

if ("currentFrame" in mySprite == false){
	trace(mySprite, "does not have a currentFrame property");
}

The “in” operator can be used to check if an object has a specific property. In the above example I test a standard Object instance and a Sprite instance for a few different properties.

I could see this operator being used when dealing with * (wildcard) datatypes and dynamic style code….

Leave a Reply

Your email address will not be published. Required fields are marked *