A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Strange error adding arrays...

  1. #1
    Senior Member
    Join Date
    May 2004
    Posts
    322

    Unhappy Strange error adding arrays...

    Code:
    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.

    Code:
    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.

    Code:
    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?
    Everybody has a story to tell, what's yours? -- http://www.filmfiler.com

  2. #2
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    New sig soon

  3. #3
    Senior Member
    Join Date
    May 2004
    Posts
    322
    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:

    Code:
    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'
    Everybody has a story to tell, what's yours? -- http://www.filmfiler.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center