我在一个视图中有两个脚本,一个脚本在一个组件内。在组件脚本中,我需要从数据中添加数字,因为它们被添加到列表中,然后在放置在视图中的标签中显示总数。如果我在第一个脚本中声明变量,组件脚本看不到它,如果我在组件脚本中声明它,标签就看不到它。我将如何声明它以便视图中的每个人都可以看到它?谢谢,金
这是代码,问题是我应该将 var MyTotal 放在哪里,以便可以在视图中的任何位置使用它:
<s:view
<fx:Script>
<![CDATA[
//if I place it here the next CDATA inside IconItemRender can't see it.
private static var MyTotal:Number=0;
]]>
</fx:Script>
<fx:Declarations>
<s:CurrencyFormatter id="usdFormatter" useCurrencySymbol="true"/>
</fx:Declarations>
<s:itemRenderer>
<fx:Component>
<s:IconItemRender ..............>
<fx:Script>
<![CDATA[
//if I place it here the Label "TotalAmountLb" can't see it.
// and it get reset to 0 everytime I call the function getInvoiceAmount.
private static var MyTotal:Number=0;
private function getInvoiceAmount(item:Object):String
{
MyTotal = MyTotal + Number(item.Amount);
}
]]>
</fx:Script>
</s:IconItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
<s:Label id="TotalAmountLb" text="{usdFormatter.format(MyTotal)}"/>
</s:view>