Flex - Adding children declared in mxml to a lower level container
I have a custom component extending Group and containing a viewstack child. The component is coded in actionscript.
When instantiating the component i开发者_高级运维n mxml like so:
<components:CustomGroup width="100%" height="100%">
<mx:HBox backgroundColor="0xDDFF11" width="100%" height="100%" />
<mx:HBox backgroundColor="0x22DD63" width="100%" height="100%"/>
</components:CustomGroup>
...I would like to override whatever function that adds the children to the parent Group and add them to the child viewstack instead but I can't seem to find where the adding occurs. Breakpoints in addChild and addElement shows that they are not called during the add.
Any directions would be much appreciated. Thanks !
I managed to do it by overriding the function mxmlContent(value:Array)
. The array is an array of all the child components declared between the parent tags.
What gets me a little worried is that when perusing inside the adobe source codes step by step, I seemed to have passed it several times but a breakpoint gets only one stop.
Anyways, it'll have to do for the time being unless I find a better solution.
Compile your project with the -keep-generated-actionscript
flag. Now you can see how your mxml code is converted to ActionScript. After some short investigation I found that the propertiesFactory
function seems to play a key role during the creation of the components, but I can't find any implementation assignment, because it's just a public function variable. :-/
Thx a lot for mxmlContent(value:Array). Seems like it works for me. This is how I bring view stack nature in Sparc contaner
public class DocumentViewer extends SkinnableContainer
{
[SkinPart(required="true")]
public var viewStack : ViewStack;
override public function set mxmlContent(value : Array) : void
{
for each (var i : IVisualElement in value)
{
addElement(i);
}
}
override public function addElement(element : IVisualElement) : IVisualElement
{
if ( element is NavigatorContent )
{
return viewStack.addElement(element);
}
else
{
var nc : NavigatorContent = new NavigatorContent();
nc.addElement(element);
return viewStack.addElement(nc);
}
}
}
精彩评论