-1

Example of the my problem.

 var array_1:Array = new Array();
 array_1[0] = [2,4,6,8];

 var array_2:array = new Array();
 array_2[0] = [10,12,14,16];
 array_2[1] = [18,20,22,24];

 // and the out come I want it to be is this  
 trace(array_1[0]) // 2,4,6,8,10,12,14,16,20,22,24

 // I did try  array_1[0] += array_2[0] but it didn't work currently   

Any suggestion would be great.

Adam Edney
  • 300
  • 1
  • 2
  • 11
  • 2
    Try `concat()` method : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#concat() – Ivan Chernykh Sep 10 '14 at 19:12
  • possible duplicate of [AS3 Fastest way to merge multiple arrays](http://stackoverflow.com/questions/7551008/as3-fastest-way-to-merge-multiple-arrays) – Anil Sep 10 '14 at 19:12
  • There is also this post as well: http://stackoverflow.com/questions/7551008/as3-fastest-way-to-merge-multiple-arrays – Anil Sep 10 '14 at 19:12

2 Answers2

0

As stated in the comments, you can use the concat method:

 var array_1:Array = new Array();
 array_1[0] = [2,4,6,8];

 var array_2:array = new Array();
 array_2[0] = [10,12,14,16];
 array_2[1] = [18,20,22,24];

 array_1[0] = array_1[0].concat(array_2[0]).concat(array_2[1]);

This, of course, is very messy looking. I am wondering why you are storing arrays inside of other arrays for no discernible reason.

Marcela
  • 3,728
  • 1
  • 15
  • 21
  • The messy reason is because array_2 is a temporary array which is likely to change a few times before it goes to the main array of array_1. < Thanks for the reply and the help – Adam Edney Sep 10 '14 at 19:28
0

This will perform what you are looking for and also allows you to add multiple rows of data to array_1 or array_2

var array_1:Array = new Array();
array_1[0] = [2,4,6,8];

var array_2:Array = new Array();
array_2[0] = [10,12,14,16];
array_2[1] = [18,20,22,24];

var combinedArray:Array = new Array();
for( var i:int = 0; i < array_1.length; i++ ) {
    combinedArray = combinedArray.concat(array_1[i]);
}
for( i = 0; i < array_2.length; i++ ) {
    combinedArray = combinedArray.concat(array_2[i]);
}

trace(combinedArray);
Anil
  • 2,539
  • 6
  • 33
  • 42