;

PDA

Click to See Complete Forum and Search --> : Strange error adding arrays...


rrrrr_rav
07-30-2006, 10:41 AM
var vProtein:Number = 0;

wProtein = new Array();
for(i=0;i<7;i++){
wProtein[i] = new Array();
for(ii=0;ii<12;ii++){
wProtein[i][ii] = 0;
}
}


The code above makes one variable called vProtein and an array called wProtein and fills that with 0's.


vProtein = addArrays(wProtein, vProtein);


Then what I'm trying to do with the above code is to pass the array and variable to a function which will add up everything in the array and put it into vProtein.


function addArrays(array, v){
var arr1:Number = array.length;
for(i=0;i<arr1;i++){
var arr2:Number = array[i].length;
for(ii=0;ii<12;ii++){
v = v+parseInt(array[i][ii]);
//trace(v);
}
}
}


That is the function which will add the values in array and put them into v.

For whatever reason, this is just not working!

When I use trace to find out 'v' in the function it works fine - I can add and remove values from the original array wProtein and v will update fine.

However vProtein which is what v is supposed to be isn't getting updated. I think this is something to do with the scope of v but I thought I was passing vProtein correctly?

Any help on this please?

dudeqwerty
07-30-2006, 11:28 AM
http://board.flashkit.com/board/showthread.php?t=697004

rrrrr_rav
07-30-2006, 12:02 PM
Thanks for that but I don't understand your code that well. As you can see in the code I have provided you, the array is defined like this:


aWeek = new Array();
for(i=0;i<7;i++){
aWeek[i] = new Array();
for(ii=0;ii<12;ii++){
aWeek[i][ii] = "";
}
}


And it does work because I have tested this. The reason it is like this is because I have to add things dynamically.

Can anyone offer more help on how to correct my code or what I'm missing from zlatans code cos I'm getting confused.

Thanks again tho'