I had to read the source code for LinkBar and its parent NavBar to understand why my LinkBar wasn’t highlighting the clicked item. Turns out, it’s because I use an ArrayCollection as a dataProvider. According to the documentation and the source code, it is possible to use an IList (such as an ArrayCollection), a String (that refers to a ViewStack in the current document) or an actual ViewStack object. But, when a selection occurs, LinkBar makes sure that we supplied a ViewStack before allowing the highlight.
Why, I have no idea. All I know is that I want to use an ArrayCollection as my dataProvider and still highlight clicked elements. I extended the LinkBar component with a tiny workaround. Feel free to use it as you wish.
StacklessLinkBar – forgive me if you find the name unoriginal.
There are 2 main ways to add non-UIComponents to a Flex Container.
1. You may add the object to a SWFLoader, which does not require its children to extend UIComponent.
2. You may add the object to Container.rawChildren.
You have to be careful with the 2nd one. First of all, know that whatever is contained in Container.rawChildren is not sized, positioned or rendered automatically. You cannot, for example, put a button in there. Another thing is that anything added to Container.rawChildren is NOT contained in the Container.children, but the contrary is true. Relying on indices to remove from the display list might be tricky.Here’s what I mean:
- You add 5 objects using Container.addChild()
- You add 5 objects using Container.rawChildren.addChild()
- You want to remove the last child of Container.rawChildren, and will use index 9 instead of 4, because rawChildren returns all 10 children.
The reason for Container.rawChildren is to add skins, not actual content. Container.getChildren() returns only elements that were added using Container.addChild(), not elements that were added using Container.rawChildren.addChild().
So my suggestion to you would be to use rawChildren only if you do not intend to remove these children later, like skins. If you wish to add interactive elements and other content, create a SWFLoader and add them to it. And if you have a UIComponent, always add it to the Container using Container.addChild().
Recent comments