The basic problem I’m trying to solve is that I have a mix of Flex & Flash components, and I have a generic function for adding a progress spinner to the component regardless. So if the component is a Container, I add it to the rawChildren, otherwise add it normally.
However, I’m running into a problem with a component that inherits from VBox. I call
cont.rawChildren.addChildAt(spinner, cont.rawChildren.numChildren);
But when I trace the children, my spinner shows up in cont.getChildren(), and the comp.numChildren obviously also increases by one. And other containers seem to work properly, even other VBox controls.
I walked through the Flex framework code and I can’t find anything to explain why this would happen, either via inheritance or timing.
Has anyone seen anything similar or can explain why rawChildren might not be predictable in this case?
Thanks.
Function:
var bcu:Number = u.numChildren;
var bce:Number = el.numChildren;
el.addChildAt(s, ((pos > -1)?pos : el.numChildren));
trace("ADD NEW SPINNER", u, el, el.numChildren, u.numChildren, bce, bcu);
Where el is either the DisplayObject or the rawChildren object of a container, and u is the original object the spinner is being attached to.
Output:
ADD NEW SPINNER BlockMovePopup1734 [object ContainerRawChildrenList] 6 5 5 4
And then:
[Fault] exception, information=TypeError: Error #1034: Type Coercion
failed: cannot convert com.misc::SbSpinner@57970a1 to mx.core.IUIComponent.
The output shows that el is correctly set to ContainerRawChildrenList (the rawChildren object for the VBox) and that the numChildren is [6,5] vs [5,4] prior to the call. This means the Sprite is being added to the content children rather than to the rawChildren.
That was fun. Found the quirk. I think maybe the
rawChildren.addChildAtfunction is a bit buggy. Found this block of text in the Container class:If I used
rawChildren.addChildit works fine for now. In both cases, the spinner was being added as the last child, but addChild does it correctly.