“in” Operator

Actionscript:
  1. var obj:Object = {name: "Joe", hobby: "Guitar", age:"80"};
  2.  
  3. if ("name" in obj){
  4.     trace(obj, " has a name property");
  5. }
  6.  
  7. if ("x" in obj == false){
  8.     trace(obj, " doesn't have an x property");
  9. }
  10.  
  11.  
  12. var mySprite:Sprite = new Sprite();
  13.  
  14. if ("currentFrame" in mySprite == false){
  15.     trace(mySprite, "does not have a currentFrame property");
  16. }

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....

This entry was posted in Operators, dynamic and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*