2 Replies Latest reply on Oct 9, 2007 11:36 AM by racingPrograms

    Dynamically pull array objects

      Hi, I'm trying to do a basic mockup of a portal chart as a Proof-Of-Concept and I'm stuck at getting the correct array element.
      I have an array of areas, broken out by weeks remaining to the event:
      { WeeksTo: "54", budget2003North: "6235", actual2003North: "4001", budget2003West: "6525", actual2003West: "4799", budget2003South: "6670", actual2003South: "4847", eventTotal: "5565" }, this repeats for multiple years.

      What I want to do is display the different years in a line chart and then populate a pie chart as a drill-down. The line chart has each element as name="event2006", name="event2007", etc. The problem I am having is that I can tell from the hitData.element.name which year was clicked on, but I can't dynamically drill into the data. For example if you clicked on a 2007 line, I have

      var year:String = e.hitData.element.name.substr(5);

      var pieDataCenter:ArrayCollection = new ArrayCollection( [
      {Product: "Actual", Total: "e.hitData.item.actual" + year + "Center"},
      {Product: "Budget", Total: "e.hitData.item.budget" + year + "Center"},

      This is to try and get {Product: "Actual", Total: e.hitData.item.actual2007Center},
      I used the D.eval() API Library and couldn't get that to work and I (and colleagues) couldn't find what I was looking for in the books we have and online.

      Is it possible to access array elements or variables this way in Flex? I know my approach is probably wrong, but as a POC to examine the feasibility of using Flex in the future, I'm interested to know if this can be done in anyway.
      The application we have is ColdFusion and we are looking at re-writing our application using a Flex front-end. As we are from a ColdFusion background we are used to drawing pages out dynamically without knowing what data to rely on. My understanding of Flex is that the Panel's have to be drawn out beforehand, you can't use ActionScript to effectively loop and build panels as needed (eg for a report showing Grandstands, one venue could have just North and South where another may have more). Is this something I have correct or am I not grasping the concepts correctly?

      Thanks in advance for your time,

        • 1. Re: Dynamically pull array objects
          chris.huston.t10 Level 3
          So you have an ArrayCollection of objects that you are charting. Try accessing your object properties with bracket notation like this:

          {Product: "Actual", Total: e.hitData.item['actual' + year + 'Center']},

          As for panels having to be drawn out beforehand, I think this is a mistake. You can use ActionScript to create any container, including panels, dynamically. It is quite easy to create containers based on run-time events. Here is a simple function to add a panel:

          private function addPanel():void {
          var newPanel:Panel = new Panel();
          newPanel.title = "New Panel";

          • 2. Re: Dynamically pull array objects
            racingPrograms Level 1
            That worked like a charm, thanks for your help.