Flex addChild() LiveDocs issue

Posted: 15/04/08

An image of Flex addChild() LiveDocs issue

I've noticed that the LiveDocs incorrectly state the type acceptable to a container's addChild() method, leading to confusion in the novice Flex development community.

In the LiveDocs, the addChild method of container states that a DisplayObject will be accepted, but the Container class immediately attempts to cast this as a UIComponent. The developer who wrote Container.as clearly only ever intended a UIComponent to be passed to the method, as he has commented his code as such:

// Throw an RTE if child is not an IUIComponent.

var uiChild:IUIComponent = IUIComponent(child);

Had this component been written entirely perfectly, a strict UIComponent type on the parameter would have been preferred over type coercion to a sub-class. The docs should probably reflect this by stating that a container's addChild method will result in a RTE if a UIComponent isn't passed to it.

Presently, developers wishing to add primitve DisplayObjects (Shape, Sprite) to Containers need to use the rawChildren object:

myPanel.rawChildren.addChild( shape );

The Container class on Adobe Flex LiveDocs

Keywords for this post: flex, flex 3, actionscript 3, Container, livedocs, UIComponent, addchild