10 Replies Latest reply on Jul 11, 2006 6:45 AM by injpix

    multi-dimensional array

    injpix Level 3
      In this multi-dimensional array (groupChannel) I am planning to have its child elements as an associative array. So say there is 12 elements inside groupChannel and each of those 12 elements are going to have child elements. Those child elements are going to contain data, so an associative array for them would be ideal. I have failed trying to do this on a number of levels.

      First, I can’t seem to be able to find the child elements data after pushing it into groupChannel.

      Second, I need to dynamically name these child elements because there can be several of them nested inside a parent element. The last section of code shows you my attempt.

      I am thinking about having these child elements inside a MC and then push the MC inside the parent element. But it seems that it should be able to work my original way.

      Any advice, please.
        • 1. Re: multi-dimensional array
          kglad Adobe Community Professional & MVP
          try:

          • 2. Re: multi-dimensional array
            injpix Level 3
            That would work just fine if I didn’t have any child elements. However I do have child elements in which some of them will be identical but belonging to a different parent element.
            I still don’t understand why that last trace statement comes up ‘undefined’. I don’t fully understand ‘casting’ datatypes but it seems that this just might be an instance that it could be used.
            Any other suggestions? Thanks again.
            • 3. Re: multi-dimensional array
              kglad Adobe Community Professional & MVP
              what's the problem. that code works fine with nodeAttrib just as you created it with child elements. eg,

              this.groupChannel[0].frequency

              should reference the frequency variable of the first element added to this.groupChannel.
              • 4. multi-dimensional array
                injpix Level 3
                I don’t think I understand kglad. In the diagram below;
                <see code>
                ...‘A’, ‘B’ and ‘C’ are the parent elements of groupChannel. I need to have the child elements of each of them to be associative arrays (Objects). All child elements will have the same attributes (channel, frequency, mode) that may have the same or different values.

                What I need from a design perspective is to allow the user to traverse thru the attributes of the child elements (eg. channel to frequency to mode, etc.) and thru the child elements (eg. ‘a’ to ‘b’ to ‘c’, etc.). The parent elements (A, B, and C) will not have any attributes. The user will also be able to traverse with these parent elements.

                So by having;
                this.groupChannel.push(nodeAttrib);

                That is assigning an associative array/Object to the parent element. Correct? So I need to do something like below;

                this.groupChannel[5].push(nodeAttrib);
                or, but doubting
                this.groupChannel[5][0].push(nodeAttrib);

                But for some reason I cannot trace any values from it. And in an addition to this I need to have ‘nodeAttrib’ to be dynamically named. So perhaps;

                this.groupChannel[5].push([nodeAttrib+genNum]);
                or, but doubting
                this.groupChannel[5][0].push([nodeAttrib+genNum]);

                But this syntactically is incorrect.
                • 5. multi-dimensional array
                  injpix Level 3
                  Is it even possible to push an associative array into an array? I am starting to think not. I can’t even get positive trace outputs from the code below.
                  • 6. Re: multi-dimensional array
                    kglad Adobe Community Professional & MVP
                    see my above messages for the correct syntax to access the arrays elements. or again:

                    • 7. Re: multi-dimensional array
                      kglad Adobe Community Professional & MVP
                      p.s. you're not really creating an associative array with your nodeAttrib statement. you're creating an object with properties.
                      • 8. multi-dimensional array
                        injpix Level 3
                        The code below is what I was trying to get at the time I started this thread. Creating an object and having an array inside of this object that’s capable of having multiple objects of its own. If you copy and paste the code below into Flash and use the Debugger when compiling you can see this object under ‘variables’.

                        “p.s. you're not really creating an associative array with your nodeAttrib statement. you're creating an object with properties.”

                        I believe that is what an associative array is at least it is according to the livedocs. It looks like you can create an instance of the Object class or the Array class to make an associative array.
                        • 9. Re: multi-dimensional array
                          kglad Adobe Community Professional & MVP
                          is your problem solved?
                          • 10. Re: multi-dimensional array
                            injpix Level 3
                            yes. Thanks for your time again kglad!