0

I have two scripts in a View, one script is inside a Component. In the Component script I need to add numbers from data as they are added to a list and then display the total in a label placed in the View. If I declare the variable in the first script, the Component script can't see it and if I declare it in the Component Script the label can't see it. How will I declare it so that everyone in the view can see it? Thanks, Kim

Here is the code, the problem is where should I place the var MyTotal so it can be used anywhere in the view:

<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>
Kim HJ
  • 1,183
  • 2
  • 11
  • 37

2 Answers2

0

Just try this:
Declare MyTotal in first script.
And in component script just try to access with outerDocument.MyTotal

Santhosh Nayak
  • 2,312
  • 3
  • 35
  • 65
0

Found the solution, I had to add [Bindable] before the declaration.

Kim HJ
  • 1,183
  • 2
  • 11
  • 37