1

The first line of this code is throwing ReferenceError #1069. "Property focusMask not found on ObjectButtonSkin and there is no default value." The "skin" variable is of type MovieClip, and the actual object instance is of type ObjectButtonSkin (which extends MovieClip).

if (skin["focusMask"] != null)
    if (skin["focusMask"] is DisplayObject)
        (skin["focusMask"] as DisplayObject).visible = false;

This was never a problem before, so I'm not sure why this is happening. The ObjectButtonSkin class is not marked as dynamic or anything else, so perhaps that's the problem? One site suggested I should be using "()" instead of "[]" to access the property, but that doesn't seem right.

Triynko
  • 18,766
  • 21
  • 107
  • 173

1 Answers1

1

A better check for the existence of focusMask would be:

if (skin.hasOwnProperty("focusMask") && skin.focusMask!=null)...

Or, if you want to be cleaner, you should extract the focusMask to a variable:

var focusMask:DisplayObject = skin.getChildByName("focusMask");
if (focusMask)
    focusMask.visible = false;
Roy
  • 325
  • 1
  • 6
  • I ran some tests and the property access operator [] throws an exception only when the class is not marked as dynamic. MovieClip and Object are dynamic, but a class that extends MovieClip is not dynamic unless explicitly marked as dynamic. hasOwnProperty is a method of Object, and will work in this case, although it will will not detect prototype properties according to the documentation. – Triynko Feb 15 '11 at 18:05
  • The getChildByName alternative will work only if focusMask is actually a child of skin and has its "name" property set to "focusMask", which is not the case in this scenario. Also interesting to know... if multiple child clips have the same name, then getChildByName returns the first one in the child list. – Triynko Feb 15 '11 at 18:11
  • ah, it was ambiguous to me whether focusMask was or not. – Roy Feb 15 '11 at 18:54
  • Actually, it probably would work in this case. The "name" property of an object is set automatically for named instances by the Flash IDE; however, dynamically attached children do not necessarily have their name property set, and it's not equivalent to the class instance property name it happens to be assigned to. For example, class instance "human", with property "arm" referencing a child clip that represents an arm, can be accessed as human["arm"], but will not be found by human.getChildByName("arm"), unless human["arm"]["name"] is set to "arm". Just a clarification for other readers. – Triynko Feb 15 '11 at 19:04