On 5/16/08, Fiouz <[EMAIL PROTECTED]> wrote:
> I'd like to specify a custom Array dataProvider to a
> mx.controls.ButtonBar instead of binding it to a ViewStack instance.
> I'm doing the following:
>
> var array:Array = new Array();
> array.push(chart); // chart is a DisplayObject instance
> array.push(grid); // grid is a DisplayObject too
> buttons.dataProvider = array;
>
> ... but NavBar.dataProvider (ButtonBar extends NavBar) doesn't seem to
> like this array of DisplayObject and throws an error, as seen in
> NavBar source code: (Flex 3.0.0)
[snip code]
> 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.