On Sat, May 17, 2008 at 6:24 PM, Manish Jethani <[EMAIL PROTECTED]> wrote: >> What is the reason behind throwing an error when an array of >> DisplayObject is given? Why would I have to wrap my DisplayObject >> instances in order to prevent this error? > > The idea was to prevent you from doing this: > > <ButtonBar> > <Button label="Chart" click="showChart()" /> > <Button label="Grid" click="showGrid()" /> > </ButtonBar> > > If the above were allowed, you'd think that your click handler would > get called, but in fact the ButtonBar (which is based on NavBar) would > actually be using the array as a data provider to create its own > Button objects; thus, your Button objects wouldn't get used as > children of the ButtonBar, they would just serve as data objects. > > So, why not the ButtonBar just use the Button objects provided by you? > Let's just say that's not the way it was designed to work. There are > complications with using user-supplied Button objects. The ButtonBar > -- or any NavBar-based component, for that matter -- needs tighter > control over its child objects. Maybe Flex could get this to work > well, but it was complicated back when it was being considered (not to > mention somewhat inconsistent with the component's design). > > By design, the data provider should be just that -- a data provider. > > Throwing an error for objects of type DisplayObject is more of a > "saving developers from shooting themselves in the foot" type of > thing, which personally I'm no big fan of, but that's just the way it > is now.
Thanks for your explanation! It's unfortunate that it is prevented though, as my goal was to selectively display ViewStack children buttons (instead of a mere ViewStack binding that displays buttons for each child), i.e.: <ButtonBar id="buttons"/> <ViewStack id="vs"> <custom:Chart id="chart" icons="...."/> <custom:Grid id="grid" icons="..."/> <custom:Form id="form"/> <!-- The buttonbar must NOT be able to select this child --> </ViewStack> I wanted my button bar not to show the "form button". For your reference, I'm wrapping "chart" & "grid" components into buttons.dataProvider: buttons.dataProvider = [ {target: chart, icon: chart.icon}, {target: grid, icon: grid.icon} ]; // wrap to prevent DisplayObject checking and in my ItemClickEvent listener: vs.selectedIndex = vs.getChildIndex(event.item.target); // unwrap through the "target" property from above My first thought was that it is cumbersome to do that wrap/unwrap, thus my email. Seems that it can't be helped if that's the way it has been designed. Is there a better way? Thanks, Regards -- Fiouz