A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: I need help Manipulating an array

  1. #1
    Member
    Join Date
    Jan 2005
    Posts
    35

    I need help Manipulating an array

    I have an array declare on my main time line named W_time in it i have several numbers.
    now what i want to do is add this numbers in the array together so i can have a sum, then i want to find the average for this numbers, am usint this code to find it, but it returns NaN....

    for(i = 0; i < 10; i++){
    sum += W_time[i];
    }
    myAverage = sum / 10;

    does this work or is there another way to add an array. Pls help.......

    Last edited by flash_ee2; 02-19-2005 at 04:56 PM.
    Post no bills

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    Do you use mx2004? if so you need to make sure you set sum to zero before you start the loop,

    Code:
    sum = 0;
    for(i = 0; i < 10; i++){
        sum += W_time[i];
    }
    myAverage = sum / 10;
    using += on an undefined variable won't work in mx2004 (but was ok in previous versions where actionscript was a little less strict)

  3. #3
    Member
    Join Date
    Jan 2005
    Posts
    35
    Thx i would not had figure that out since i have been using flash for a while and now switch to 2004 is pain to make the transition....by the way it worked....
    Post no bills

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