5 Replies Latest reply on Aug 2, 2007 11:56 AM by zzdobrusky

    How to return 2-D Array in function

    zzdobrusky Level 1
      Hello,
      is it possible to return 2-D array in function? I have this but returns undefined, all testing inside function works though,
      I am calling function by:

      imageThumbsFineArtArr = calculateThumbWidths(numOfSeriesFineArt, numOfImagesFineArtArr, "thumbImageFineArt");
      thanks for any help

        • 1. Re: How to return 2-D Array in function
          Level 7
          Hi zzdobrusky,

          I took a quick glance at this and off the top I saw nothing that should
          be preventing you from returning the array. Even if your loops never
          ran, you should still see an array object returning. One thing you can
          try is to define your variable (thumWidthsArr) outside of the function.
          You can also try the return function as a function rather than a
          language construct:

          return (thumbWidthsArr);

          Good luck,
          Patrick

          zzdobrusky wrote:
          > Hello,
          > is it possible to return 2-D array in function? I have this but returns
          > undefined, all testing inside function works though,
          > I am calling function by:
          >
          > imageThumbsFineArtArr = calculateThumbWidths(numOfSeriesFineArt,
          > numOfImagesFineArtArr, "thumbImageFineArt");
          > thanks for any help
          >
          >
          >
          > function calculateThumbWidths(numOfSeries:Number, numOfImages:Array,
          > actualImageHolder:String):Array {
          > var thumbWidthsArr:Array = new Array();
          > for(i=0; i < numOfSeries; i++) {
          > thumbWidthsArr = new Array();
          > for(j=0; j < numOfImages
          ; j++) {
          > target_mc = actualImageHolder + i + "-" + j;
          > trace("target_mc = " + target_mc);
          > trace("this[target_mc]._width = " + this[target_mc]._width);
          > thumbWidthsArr [j] = this[target_mc]._width;
          > trace("thumbWidthsArr[" + i + "][" + j + "] = " + thumbWidthsArr
          [j]);
          > } // End for-loop
          > } // End for-loop
          >
          > return thumbWidthsArr;
          > } // End function calculateThumbWidths()
          >

          --
          http://www.baynewmedia.com
          Faster, easier, better...ActionScript development taken to new heights.
          Download the BNMAPI today. You'll wonder how you ever did without it!
          Available for ActionScript 2.0/3.0.
          • 2. Re: How to return 2-D Array in function
            kglad Adobe Community Professional & MVP
            trace(imageThumbsFineArtArr ) is undefined or it's an array of undefined elements?
            • 3. Re: How to return 2-D Array in function
              zzdobrusky Level 1
              Hi,
              thanks all for reply, all traces inside function are giving me the correct values, its when I call function

              imageThumbsFineArtArr = calculateThumbWidths(numOfSeriesFineArt, numOfImagesFineArtArr, "thumbImageFineArt");

              and then check array members of imageThumbsFineArtArr [j] thats giving me undefined,
              thanks,
              Z.
              • 4. Re: How to return 2-D Array in function
                kglad Adobe Community Professional & MVP
                1. imageThumbsFineArtArr = calculateThumbWidths(numOfSeriesFineArt, numOfImagesFineArtArr, "thumbImageFineArt");

                is passing 3 defined parameters of the correct types?

                2. trace(imageThumbsFineArtArr) immediately after statement 1, traces an array of undefined?

                3. when you trace this[target_mc]._width you see numbers?
                • 5. Re: How to return 2-D Array in function
                  zzdobrusky Level 1
                  regarding 2. yes it is undefined after statement 1. and it shows correct numbers after 3.

                  I already resolved the issue, it may not be clean but it works, function is not returning anything and I am changing array imageThumbsFineArtArr inside the function as a global variable and each array member i, j separetly...
                  Thanks again,
                  Zbynek