4 Replies Latest reply on Mar 4, 2009 6:57 PM by kemah551

    ArrayCollection trouble

    kemah551
      I'm having trouble rendering a column chart with an ArrayCollection. I need to load the value of a label's results into the array to render the first chart bar while I have a static value defined for the second bar.

      Here is a code snippet:
      <mx:Script><![CDATA[
      import mx.collections.ArrayCollection;
      [Bindable]
      public var expenses:ArrayCollection = new ArrayCollection([

      {Month:"Default Rate", Profit:15.00, Expenses:"{label1.value}"} //label1.value is where I want expenses to updated dynamically
      ]);

      private function setTitles():void {
      la1.title="Default Rate";
      }

      ]]></mx:Script>

        • 1. ArrayCollection trouble
          Francisc Level 3
          Try: Expenses:label1.text. (no quots or {})

          If label1 reffers to a Label control, text is the propery you are looking for, not value.
          • 2. Re: ArrayCollection trouble
            kemah551 Level 1
            Thanks MASH,

            I've implemented your suggestion and have a new issue. "cannot access a property or method of a null object reference".

            Do you know a fix for this?

            Thanks
            • 3. ArrayCollection trouble
              Francisc Level 3
              This is because you need the Label control to be created.
              You should have the code like this within the Script tag:

              public var expenses:ArrayCollection;
              //other vars if any

              private function init():void
              {
              expenses=new ArrayCollection([{Month:"Default Rate", Profit:15.00, Expenses:label1.text}]);
              }

              Also in the Application tag you need to add: creationComplete="init()".

              The reason for the error was that variables are declared first and afterwards the components. When the ArrayCollection was declared, label1 did not exist, hence the error. Now you are declaring the var as you did before, but assigning values to it after the application was created. :)

              Good luck!
              • 4. Re: ArrayCollection trouble
                kemah551 Level 1
                Thanks for your help. It worked like a charm.