4 Replies Latest reply on Dec 30, 2010 6:46 AM by Gregory Lafrance

    Input array affected by function even though it's not returned

    Fayena Level 1

      I have it set up to call the array foalT 4 times to combine it with different results.  foalT is a multidimensional array with each element 4 elements long.   It works perfectly the first time the function is called foalTotal is correct.  The other times foalT is empty.  It appears the problem is happening when I use original.shift() and then recursively call the function but I have no idea why original is getting passed back into the foalT array.  Any help would be appreciated. 


      var foalTotal:Array=Combine(foalWA,foalT);

      var foalTSC:Array=Combine(foalWASC,foalT);

      var foalTDC:Array=Combine(foalWADC,foalT);

      var foalTBC:Array = Combine(foalWABC,foalT);


      function Combine(cross:Array,original:Array):Array{

           var k:uint=0;

           var total:Array = new Array;

           trace("foalT Length:" + original.length);

           if (original.length!==0){


                for (var i:uint=0; i<cross.length; i++){

                     for (var j:uint=0; j<=3; j++){

                          total[k]= cross[i].slice();



                     }//end inner for

                }//end outer for


           return (Combine(total,original));

           }//end if



      }// end fuction