[CS4] Find biggest variable?
How could i find the biggest variable out of lots of them
i have a few variables and a finalvar
each has a value (differs)
what i want is to get the biggest
name1 = 10
name2 = 33
name3 = 21
name4 = 100
finalvar = name4
i would want name 4 (the biggest) to become the value of finalvar
how would i do this :S
TYVM for help
Since I'm not trying this out in Flash, you may have to play around with the code a little bit to make sure I used the right syntax, but this should do it for you.
ps. You can add the numbers to the array in any way you want... in fact, you could just add them WITHOUT using variables.... just .push() the number onto the array instead of storing it in a variable.
Basically, you're just putting the numbers in an array and sorting them... that puts them in Ascending order, so you'd have to find the LAST number. Instead, you just reverse the array and the largest number will always be at .
var name1:Number = 10;
var name2:Number = 33;
var name3:Number = 21;
var name4:Number = 100;
var myArray:Array = new Array();
myArray.sort(Array.NUMERIC); //Array.NUMERIC is important because arrays, by default, sort as if all of their values were strings.
trace(myArray); //output: 100;
Last edited by Taidaishar; 10-10-2008 at 03:40 PM.
i had to mod it a little but it worked
Click Here to Expand Forum to Full Width