我在View中有两个脚本,一个脚本在Component内部。 在组件脚本中,我需要在数据添加到列表中时添加数字,然后将总数显示在放置在视图中的标签中。 如果我在第一个脚本中声明该变量,则组件脚本无法看到它,并且如果我在组件脚本中声明它,标签将无法看到它。 我将如何声明它,以便视图中的每个人都能看到它? 谢谢, 金Flash Builder 4.5中的局部变量
下面是代码,问题是我应该在哪里放置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>
我认为你的问题没有任何意义。首先明确你的问题。 – Exhausted
请详细解释,并显示一些代码。 – JeffryHouser
如果我明白这个权利,你应该给你的组件一个id。用id,你可以引用组件内的变量。其他方式是从组件到查看的调度自定义事件。 –