Arrays

hi,

is it possible to store an array inside another array? i have an array which holds various filters and i want to apply cmFilter to [4] of that array

    var matrix:Array = new Array(amount, 0, 0, 0, 0, 0, amount, 0, 0, 0, 0, 0, amount, 0, 0, 0, 0, 0, amount, 0);
    var cmFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
    path.curr_effects[4] = [cmFilter];
    path.curr_chan.filters = path.curr_effects;

cheers.
Gareth

you can easily create a multidimensionall array in flash like this.

a1 = [1,2,3,4];
a2 = [5,6,7,8];
a = [a1,a2];
trace(a[0][1]);// will trace 2
//OR
a3 = [[1,2,3],[4,["a","b"],6],[7,8,9]];
trace(a3[2][2]);// will trace 9;
trace(a3[1][1]);// will trace   a,b (this is actually another array);
trace(a3[1][1][0]);// will trace a;

Hope it’s clear enough, 'cause I don’t understand your problem with the code :).

hi thanks for you reply… basically i have an array called curr_effects and i want to add the array cmFilter to its number 4 slot. and then apply the curr_effects array to [COLOR=#000000][COLOR=#0000bb]curr_chan[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]filters[/COLOR][/COLOR]

Ok. I now understand. So. The filters parameter of an MC is an array of filters like (dropshadow, glow etc).
Here’s your problem - path.curr_effects[4] = [cmFilter];
You add as the fourth element of the curr_effects array another array with only one element cmFilter. You need to add directly the cmFilter to the array because in the end you will use the array of filters. An array of arrays of filters is not useful :). So you actually don’t need to store an array inside another array.
So the code would look like

var matrix:Array = new Array(amount, 0, 0, 0, 0, 0, amount, 0, 0, 0, 0, 0, amount, 0, 0, 0, 0, 0, amount, 0);
    var cmFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
    path.curr_effects[4] = cmFilter;
    path.curr_chan.filters = path.curr_effects; 

Writing this I’ve realized that you might want your path.curr_effects to hold multiple possible combinations of filters. Because this might be the case where you would want to keep an array inside another array.
So storing your array was the good way, as long as you previously defined path.curr_effects = new Array();
If you done this you will be able to set Strings, numbers, arrays or objects as elements of that array.
so path.curr_effects[3] = [1,2,3]; // stores another array at the fourth element of path.curr_effects array.
In this case the problem is when you set your current array to the filters. You need to get only the array of filters. If inside a multidimensional array you will need to speciffy the element like this

var matrix:Array = new Array(amount, 0, 0, 0, 0, 0, amount, 0, 0, 0, 0, 0, amount, 0, 0, 0, 0, 0, amount, 0);
    var cmFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
    path.curr_effects[4] = [cmFilter];
    path.curr_chan.filters = path.curr_effects[4]; 

Hope this helps you.