Flex addChild() LiveDocs issue
Posted: 15/04/08
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
Popular categories:
Recent posts:
- Mac OS find files using regex
- ADB device driver won't install
- Eclipse: An error has occurred. See the log file .metadata/.log
- Updated blinkbox iPad app
- Nexus 7 doesn't appear in adb devices list
- Improve the keyboard in the Samsung ICS update
- 403 Forbidden error on Mac web server
- Getting error with manually created NIB?
- Adding/removing items from PATH on Mac
- Presenting at Flash Oxford
- more...
Publications:
Places you'll find me:
Archive:
- April 2024
- March 2024
- February 2024
- January 2024
- December 2023
- November 2023
- October 2023
- September 2023
- August 2023
- July 2023
- June 2023
- May 2023