3 Replies Latest reply on Oct 2, 2009 5:47 AM by Ned Murphy

Array needed?

I need to make a bit of code that can decide where a number falls in a set of ranges eg

target number = 11

groupA = 1-9

groupB = 10-19

groupC= 20-29 etc.

..I need the code to decide which number range it is in and then apply a function to the movieclip 'linked' to the group, so in this example groupBMovieclip would play.

I think I can sort out making the clip play, but I am trying to find the best way to go about making the number ranges work (I have tried using 'if' functions, but I have a total of 60 number ranges, and I think flash has a problem trying to deal with so many, and it was suggested to me that an array might be a better way to do this. Any ideas!? Thanks, R.

• 1. Re: Array needed?

An array may not be necessary, though a different group naming scheme might be better, using numbers instead of letters since you will run out of letters at Z.

If you were to have your groups named Group0, Group1, Group2, etc, then determining which group a number falls into might be as simple as rounding down diviision by 10.

groupName = "Group"+String(Math.floor(numValue/10));

Here's a quick check on seeing if that works if you want to plug it in and run it....

var numValue = 4;

for(i=0; i<20; i++){
trace(numValue+"  "+"Group"+String(Math.floor(numValue/10)));
numValue += 7;
}

If having GroupA, GroupB, etc is necessary, then having an array could come in handy since it will be up to you to decide what happens after you hit GroupZ... you could still use the same apperoach to determine which index of the array the number belongs to, which would be the group appendage (A thru....?).

• 2. Re: Array needed?

Wicked thanks, I was just using A,B etc for an example but it's working fine with my actual code. Thanks once again!

• 3. Re: Array needed?

You're welcome