A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Simplify?

  1. #1
    Can anyone optimize this code?

    if (var1>var2 and var1>var3 and var1>var4 and var1>var5) {
    biggest = var1;
    } else if (var2>var1 and var2>var3 and var2>var4 and var2>var5) {
    biggest = var2;
    } else if (var3>var1 and var3>var2 and var3>var4 and var3>var5) {
    biggest = var3;
    } else if (var4>var1 and var4>var2 and var4>var3 and var4>var5) {
    biggest = var4;
    } else if (var5>var1 and var5>var2 and var5>var3 and var5>var4) {
    biggest = var5;
    }

    all i want is the biggest of vars 1-5 to be put into a textfield of some way of signifying which is biggest.
    Thanks

  2. #2
    Actkid
    Join Date
    Feb 2001
    Location
    Surat
    Posts
    764

    Post here is little bit diff code.

    this.vari0 = 4
    this.vari1 = 42
    this.vari2 = 455
    this.vari3 = 34
    this.vari4 = 114
    this.myArray = new Array();

    for(i=0; i<5; i++) {

    this.myArray[i] = eval("vari" + i);
    }
    myArray.sort();
    trace(myArray[4]);

    Stop();


    CIAOOO

  3. #3
    Thank you very much for the help, but when i tried it, it didnt come through. (ignore the +57+63 etc

    temparray = [maintextmc.textWidth+20,namemc.textWidth+57,opinio nmc.textWidth+63];
    temparray.sort();
    boxwidth = temparray[temparray.length]+16;

    any help would be greatly appreciated1

    Thanks Phil

  4. #4
    Senior Member
    Join Date
    Nov 2001
    Posts
    667
    Change this line:

    boxwidth = temparray[temparray.length]+16;

    to:

    boxwidth = temparray[temparray.length-1]+16;

    Array indexes are zero based, the length is one based. ie an array with a length of 1 has one item at index 0.

  5. #5
    i tried that but the prob was it wasnt sorting em right
    i came up with one a bit smaller using math.max thanks all

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