views:

132

answers:

1

I want to make a custom container, usable in MXML like:

<local:MyContainer>
  <s:Label/>
  <s:Button/>
  ...
</local:MyContainer>

...but I'd like to be able to catch when the children are added so that I can control stuff like when & where they're added.

I tried overriding addChild(), addChildAt(), addElement(), addElementAt(), (extending the Group class) but they only fire when you add elements specifically with those functions - the application launches and the label, button, etc, end up in MyContainer without calling these functions.

How do I control the addition of sub-components via MXML? Am I on the wrong track - should I be writing a custom layout and/or skin instead?

A: 

You could try to overwrite the setter of the mxmlContent-Array. Probably this is used instead of addChild()...

hering
Thanks for your answer - you're right, it calls that. Looking at the source code for Group, it appears that the Group internally uses the private function elementAdded() to do the real leg-work of adding an element. In other words, the SDK cheats to avoid calling addElement for MXML elements.However, the comment "This method is used internally by Flex and is not intended for direct use by developers." in front of the method makes me uneasy about trying to use it. Must learn more about custom layouts...
Kelsey Rider