5 Replies Latest reply on Mar 13, 2008 12:22 PM by ntsiii


      So say I have an ArrayCollection like this

      public var dp:ArrayCollection = [ {Candidate_20:"345"},
      {Candidate_21: "450"} ];

      Can I access the id i.e. the Candidate_20 part of the array as a variable?

      I am trying to use it in a loop to build a graph, I will not know the Candidate no before the query is run the easiest way would be to output the arraycollection id toString() not sure if it's possible though spent a hell of a long time looking over the forums and searchs.

      Thanks for any help

        • 1. Re: ArrayCollection
          Sreenivas R Adobe Employee
          have you tried the following?

          for(var index:int = 0; index < dp.length; ++index)
          for (var property:String in dp[index])
          trace(property); //this would give you Candidate_20, Candiate_21
          trace(dp[index][property]) //gives 345, 450
          • 2. Re: ArrayCollection
            Crawdevil Level 1
            Hi sorry it's been a while been working on other things.

            Unfortunatly that didn't work my code is

            private function createLines():void
            var ls:LineSeries = new LineSeries();
            lineChart.series = [ls]; // associate the array
            var tempObj:Object; //create a series for each series of data
            for(var index:int = 0; index < dataProvider.length; ++index)
            for (var property:String in dataProvider[index])
            ls = new LineSeries();
            ls.displayName = property;
            ls.yField = property;
            lineChart.series[index] = ls;

            I'm trying to dynamically create a chart and use the dataProvider labels as the ls.displayName and ls.yField but it will not create the chart it works fine if i pass the parameters in manually.

            Appriciate any help

            • 3. Re: ArrayCollection
              Sreenivas R Adobe Employee
              Have you debugged to see you are not getting what you want?

              If possible create a sample app and test it. If it doesn't work you can either post of send me the code to sreenivas.ramaswamy@gmail.com
              • 4. Re: ArrayCollection
                Crawdevil Level 1
                Hi Sreenivas R

                tried to run a trace I get this output

                TypeError: Error #1009: Cannot access a property or method of a null object reference.
                at voteHourGraph/createTrace()
                at voteHourGraph/creationComplete()
                at voteHourGraph/___Application1_creationComplete()
                at flash.events::EventDispatcher/dispatchEventFunction()
                at flash.events::EventDispatcher/dispatchEvent()
                at mx.core::UIComponent/dispatchEvent()
                at mx.core::UIComponent/set initialized()
                at mx.managers::LayoutManager/doPhasedInstantiation()
                at Function/ http://adobe.com/AS3/2006/builtin::apply()
                at mx.core::UIComponent/callLaterDispatcher2()
                at mx.core::UIComponent/callLaterDispatcher()

                It seems there is nothing in property to be accessed?

                Thanks Clive
                • 5. Re: ArrayCollection
                  ntsiii Level 3
                  Sreenivas is suggesting that you debug the code to find out where the error is ocurring.

                  Put a breakpoint at the top of the function and step through it.

                  Or sprinkle some trace statements in the cod until you can pin down the problem.