0
votes

What is the difference between Child and Element of a container? Why do the containers like Spark VGroup have different sets of methods for both Child and Elements?

Can anyone explain me the difference in the simplest way? Thanks in advance..

2
Hey please see my answer and please accept it if answers your question. Thanks. - Gurtej Singh

2 Answers

0
votes

The addChild method is used for adding a DisplayObject, which is a method from pure actionscript. So you would typically add Sprite, MovieClips etc. Widely used in action script based projects

The Flex classes like VGroup are written on top of the base actionscript classes, and therefore have an extra addElement method to be able to add an IVisualElement, which can also be an FXG for example, or other Flex based components such as UIComponent, Group etc.

However, I doubt that calling addChild on a VGroup will actually provide desired results and may result in errors.

Hope this answers your question.

0
votes

The type IVisualElement and with it all the *Element methods from IVisualElementContainer were introduced in Flex SDK 4.0 as part of the spark layout and lifecycle features.

You are still free to build your own components based on UIComponents without having the spark features and only with the *Child methods.

All classes that extend DisplayObjectContainer of course inherit the *Child methods but in classes like Group (and SkinnableComponent) those methods have been overwritten to throw an error, as one needs to use the *Element methods to use the Spark features.

As Flex 4 supports using the MX layout as well as the Spark layout (there are options to use only one of them or both side by side when compiling) those methods could not be marked as deprecated in Group and SkinnableComponent, wich would at least trigger a compiler warning instead of a runtime error.