0
votes

Is there a way to access children's properties of a custom components from mxml and not from the actionscript.

For example, i have a component "A"

<s:Group>
   <mx:UIComponent id='childA'/>
   <mx:UIComponent id='childB'/>
</s:Group>

And somewhere in the application i want to do something like this

<s:HGroup>
   <components:A>
      /*I want to access properties of this children objects*/
      <childA width="20"/>
      <childB color="0xFFFFFF"/>
   </components:A>

   <components:A>
      /*And here too*/
      <childA width="60"/>
      <childB color="0x000000"/>
   </components:A>
</s:HGroup>
1

1 Answers

1
votes

You can do this in ActionScript; but not in MXML. In ActionScript:

componentAInstance.childA.width = 20;
componentAInstance.childB.setStyle('color',0xFFFFFF);

This is what we call a horrible break in encapsulation; becahse the "parent" should not need to know about the implementation details of its children.

ComponentA should know how to size and position its own children; in this chase childA and childB. It should not need help from ComponentA's parent.

You may find benefit in reading this blog post about how component's should communicate with each other.