views:

22

answers:

1

Hello all,

I have the following mxml (Omitted some parts for brevity purpose):

<fx:Script>
    [Bindable]
    private var _dataSet:IDataSet;

    public function set dataSet(value:IDataSet)
    {
      _dataSet = value;
    }

    private function getColorItem(itemName:*):String
    {
      if (itemName == "Research")  return "#31e5fc";
      ...
      else {
        trace("Unknown item : " + itemName);
        return #ffffff;
      }
    }  
</fx:Script>
<spark:RichText color="{this.getColorItem(this._dataSet.name)}" ... />

Does anyone knows why the color is not being applied? If I change the binding to the method, for a constant String (i.e. #31e5fc), it works allright?

I need the color to change according to the data received by this component. Any help on where I am doing a mistake is much appreciated.

+1  A: 

You've got a couple of odd things here. First, your getColorItem function should return a uint rather than a String. Second, why not just call getColorItem from your dataSet setter? Something like this:

public function set dataSet(value:IDataSet)
{
    _dataSet = value;
    myRichText.setStyle("color", getColorItem(_dataSet.name);
}

Hope that helps.

Wade Mueller
I just figured out my errors. I had forgotten to set an id for the RichText. Thanks!
dornad