views:

35

answers:

1

When I create a custom component, I define a property which is array that could accept values from the enumeration, see code below:

[Inspectable(type="Array", defaultValue="day, month", enumeration="day, week, decade, month, year")]
public var selectionMode:Array;

I would like to know how I can pass array of values to my component from MXML application that uses my custom component.

I expect that it should be something like:

<custom:component selectionMode="[day, year]" />

But it doesn't work... Any idea?

+2  A: 

inspectable metadata is just for code hinting purposes; and has nothing to do with the actual passing of data into the component.

To define a string of arrays in-line you need to use single quotes to enclose each string, like this:

<custom:component selectionMode="['day','month']" />

Most people will not define an array in-line, though. They'd do so in ActionScript, like this:

[Bindable] protected var myArray:Array = [ "day", "year"];

In MXML they reference it like this:

<custom:component selectionMode="{myArray}" />
www.Flextras.com
Thank you! This is what I was looking for!
MinimeDJ
Why did you put [Bindable]? Is there a need for it?
MinimeDJ
Can you do a Bindable array? I think if you use [Bindable] you have to use an ArrayCollection, don't you?[Bindable] means that the variable is open to databinding - meaning if you say {myVariable} in your MXML somewhere then any time that variable changes it's automatically updated in your MXML component.
Myk
@MinimeDJ I put in Bindable because it is a common approach in Flex development. The curly brackets in MXML mean to use binding on the variable. If the variable is not Bindable you will get a compiler warning. The only reason you *NEED* to make it Bindable is you want to change said values during runtime and have the custom component automatically pick up the changed value. [of course you'll need to program the custom component to update itself when the value of said property changes]
www.Flextras.com
@myk Any variable in Flex can be made Bindable; it is not limited to ArrayCollections. For example, the dayNames array on the DateChooser component (or the Flextras Calendar Component).
www.Flextras.com