Search code examples
actionscript-3apache-flexactionscriptaddchild

ActionScript: programmatically adding children to a `mx:ViewStack`


I have a Flex mx:ViewStack that have some Flex children, but I want to add more using ActionScript.

var o:MyCanvas = new MyCanvas;
o.id = 'modRipley';
viewStack.addChild(o);
o = new MyCanvas;
o.id = 'modNewt';
viewStack.addChild(o);
o = new MyCanvas;
o.id = 'modGorman';
viewStack.addChild(o);

Stepping through, I don't see any increase to the childDescriptors member (nor the _childDescriptors) and:

viewStack.getChildByName('modNewt');

just returns null.

I am using the Flex 3.5 SDK.


Solution

  • Instead of assigning o.id = 'modNewt'; use o.name = 'modNewt'; and try to access child by using viewStack.getChildByName('modNewt');. It should work.