tags:

views:

21

answers:

1
+1  Q: 

Flex: Show label

I have an object with a property STATUS which is of a type String, STATUS holds 1,2 or 3

Now each value for STATUS has its value to show so;

1 => 'Inactive'
2 => 'Active'
3 => 'Suspended'

Meaning that on a form I'd display those textual value instead of just 1,2 or 3. I hold the value in an ArrayCollection

What would be the best and most efficient way to show those values binded in a form, so that:

<s:Label text="Status: {object.status}"/>

For object.status = 1, would show the following in the label: Status: Inactive I need it to be bindable as well.

In a datagrid I'd use a labelFunction to achieve this, but what to use in a Label?

+1  A: 

You could add a getter function in the object's class and bind to that instead in the label.

    [Bindable (name="statusStringProperty")]
    public function get statusString():String
    {
        var sRet:String = "";           
        switch(status)
        {
            case 1:
                sRet = "Inactive";
                break;
            case 2:
                sRet = "Active";
                break;
            case 3:
                sRet = "Suspended";
                break;
            default:
                sRet = "";
        }
        return sRet;
    }

<s:Label text="Status: {object.statusString}"/>
Jason W
@Jason W nice one. Forgot about binding a function. Thanx
Adnan
@Adnan - no worries, glad to help
Jason W