开发者

Data binding from a method in Flex

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 mis开发者_如何学Pythontake is much appreciated.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜