2 Replies Latest reply on Jan 12, 2016 3:29 PM by MelisaAS3

    Merging Arrays

    MelisaAS3

      Hi,

      I am new to as3 and need your help.

      I would like to combine two arrays such that the elements of each array follow each other in alternating order.

      For example, if Array1=(1,2,3) and Array2=(A,B,C), I would like my combined Array to  look like (1,A,2,B,3,C).

      When I use the concatenate function the arrays are combined like this: (1,2,3,A,B,C) and this is not what I want.


      Please let me know if you know the answer.

      Thank you so much.

      Melisa

        • 1. Re: Merging Arrays
          Colin Holgate MVP & Adobe Community Professional

          I don't think there is a single function that does what you want, but there are various ways you could solve the problem. Are you assuming that the arrays are always the same length? If you are, here's one way:

           

          var array1:Array = "1,2,3";

          var array1:Array = "A,B,C";

          var combined:Array = [];

          var i:int;

          for(i=0;i<array1.length;i++){

          combined.push(array1[i]);

          combined.push(array2[i]);

          }

           

          After that, the array 'combined' would be how you wanted the array to be.

          • 2. Re: Merging Arrays
            MelisaAS3 Level 1

            Dear Colin,

             

            Thank you soo much! It worked! I am very grateful for your quick and helpful response.

            I have been trying to do this since the last 3 hours!

            Thanks!

            Melisa