Monday, March 30, 2009

ActionScript: Why can't you access a Button's children

Have you ever wondered why you have to use a MovieClip instead of a Button symbol type when you want to access the child elements? Here's the explanation...

MovieClip

The MovieClip class in ActionScript has the following inheritance tree:
MovieClip - Sprite - DisplayObjectContainer - InteractiveObject - DisplayObject - EventDispatcher - Object
The ability to interact with child elements of the movie clip come from the DisplayObjectContainer class, which has the numChildren property and the addChild, addChildAt, contains, getChildAt, getChildByName, getChildIndex, removeChild, removeChildAt, setChildIndex, swapChildren, and swapChildrenAt methods.

SimpleButton

The SimpleButton class in ActionScript has the following inheritance tree:
SimpleButton - InteractiveObject - DisplayObject - EventDispatcher - Object
None of the classes in this hierarchy contain methods to deal with child elements.

1 comment: