访问未定义的属性 - Flex 4.6

时间:2012-04-13 23:58:08

标签: flex mobile actionscript

Flex 4.6移动应用程序

我收到错误“访问未定义属性PrepForDisplay”

在我的声明标签中我有

 <s:CurrencyFormatter id="PrepForDisplay"
     currencySymbol="" 
     useCurrencySymbol="true"
     negativeCurrencyFormat="0"
     positiveCurrencyFormat="0"/>

在我的MXML部分,我有

<s:List id="lst" dataProvider="{dp}" useVirtualLayout="true" width="100%" height="95%" top="30" alternatingItemColors="[#66FFFF, #33CCCC]">
<s:itemRenderer>
<fx:Component>
       <s:ItemRenderer>
    <s:HGroup  gap="10">
    <s:Label text="{data.Period}" />
    **<s:Label text="{PrepForDisplay.format(data.Payment)}" />**
    </s:HGroup>
  </s:ItemRenderer>
</fx:Component>

 

粗线表示错误。 如果我将其更改为Number(data.Payment).toFixed(2)一切正常。 我已经使用currencyFormatter,就像我在其他视图上获得成功一样。我甚至可以在函数中使用它,但是当我尝试在标签中应用它时,我得到了错误。

有什么想法吗?

欢呼声,

1 个答案:

答案 0 :(得分:3)

我的猜测是,它是一个范围错误,换句话说,格式化程序是在组件的范围内创建的,它创建了列表,而itemrenderer被实例化为列表。因此它不知道在itemrenderer中引用的变量(PrepForDisplay)。

要解决此问题,只需在itemrenderer中移动CurrencyFormatter标记:

<s:ItemRenderer>
<fx:Declarations>
<s:CurrencyFormatter id="PrepForDisplay"
 currencySymbol="" 
 useCurrencySymbol="true"
 negativeCurrencyFormat="0"
 positiveCurrencyFormat="0"/>
</fx:Declarations>
<s:HGroup  gap="10">
    <s:Label text="{data.Period}" />
    <s:Label text="{PrepForDisplay.format(data.Payment)}" />
</s:HGroup>

或者只是在单独的文件中定义itemrenderer。

相关问题