2011-11-20 85 views
0

我在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> 
+0

我认为你的问题没有任何意义。首先明确你的问题。 – Exhausted

+0

请详细解释,并显示一些代码。 – JeffryHouser

+0

如果我明白这个权利,你应该给你的组件一个id。用id,你可以引用组件内的变量。其他方式是从组件到查看的调度自定义事件。 –

回答

0

找到解决方案,我不得不在声明前添加[Bindable]。

+0

K罚款。我有点忙,所以没有尝试过你的代码... –

0

就试试这个:
中首先声明MyTotal脚本。
并在组件脚本只是尝试访问与outerDocument.MyTotal

+0

不,我得到一个错误说:1178:尝试访问不可访问的属性MyTotal通过静态类型视图引用 –

+0

@KimHJ认为你必须声明'MyTotal'为'public'或'protected' –

+0

试过,得到错误1120和1178 –