Error: Multiple sets of visual children have been specified for this component (component definition and component instance).
is thrown by Flex when developers attempt to define children at two different places for a container. Suppose we have MyFirstBox extending HBox as follows:
MySecondHBox.mxml
<mx:HBox mx="http://www.adobe.com/2006/mxml">
<mx:Button label="Button in declaration"/>
</mx:HBox>
And we are trying to use MyFirstBox in another container like this
<Application>
<MyFirsthBox>
<mx:Button label="Button in Instance" />
</MyFirstHBox>
</Application>
Flex throws the exception because it finds that in the declaration as well as in the instance inside the application child buttons are being added.
This may be very easy to catch but where it bites is when we are trying to create a hierarchy of MXML components. Suppose we try to create a second HBox derived from MyFirstBox as follows
MySecondHBox.mxml
<MyFirstHBox xmlns="*" mx="http://www.adobe.com/2006/mxml">
<mx:Button label="Button in derived comp" />
</MyFirstHBox>
This is also not allowed as it falls under the same category and Flex throws the same exception. The workaround is to define children only in the leaf derived class.
Any solution?