dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Highest And Lowest Vars

  1. #1
    ____________
    Join Date
    Sep 2004
    Location
    Hells Kitchen
    Posts
    191

    Highest And Lowest Vars

    I have about 200 variables that create a graph, and the variables come from different categories with different ranges of values. (ex: values ranging from 1-4, values from 23-50, etc.)

    What I need to do is get the highest value and the lowest of all the vars so I know the range to dynamically set the graph at.

    I know how to do it on vars like this ( var1=5, var2=3) but he var names are very different. What I really want is to dump all of the vars in an array, then get a Math.findMax, and a Math.findMin, checking them at a ++ rate.

    Lets see what you Flash kitters can do.
    Last edited by FlashGod.com; 03-08-2005 at 04:41 AM.
    _

    __________________

  2. #2
    ActionScript Insomniac
    Join Date
    Jan 2003
    Location
    43d03.21'N, 89d23.65'W
    Posts
    1,173
    Try something like this:
    Code:
    function getMax( a : Array) : Number {
        var m : Number = a[0];
        for(var i in a) {
            if(a[i] > m) m = a[i];
        }
        return m;
    }
    This uses the for..in iteration, which ought to be the fastest available.
    Unless otherwise specified, all code goes in Frame 1 of main timeline. FlashGizmo.com

  3. #3
    ____________
    Join Date
    Sep 2004
    Location
    Hells Kitchen
    Posts
    191
    How do i get all of my vars (that Ive loaded from txt files), into that array?

    If this helps, here are a few of the vars (of 196) :

    D1_H0_CUM=3
    D1_H0_SWE1=2.5
    D1_H0_SWE2=3.5
    D1_H6_SWE3=1.5
    D1_H6_SWE4=1.9
    D2_H0_SWE5=3.8
    D2_H0_SWE6=2.7
    D3_H0_SEC1=7.4

    Thanks
    _

    __________________

  4. #4
    Member
    Join Date
    Mar 2005
    Location
    Berlin
    Posts
    34
    I assume you loaded them into an empty movieclip mc. Then you can do something like this:

    var aVals = new Array ();
    for (var i in mc)
    aVals.push (mc [i]);

    This isnt the fastest way but the easiest one.
    ~Scimmer ();

  5. #5
    ____________
    Join Date
    Sep 2004
    Location
    Hells Kitchen
    Posts
    191
    their actually loaded on the root. could itt still be done without grabbing all root level vars?
    _

    __________________

  6. #6
    Member
    Join Date
    Mar 2005
    Location
    Berlin
    Posts
    34
    Cant you just change the loading function to load the variables into an empty movieclip?
    ~Scimmer ();

  7. #7
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Or just bite the bullet.

    ary = [D1_H0_CUM, D1_H0_SWE1, D1_HO_SWE2, // etc... ];

    And next time, name your variables consistently to avoid this kind of nonsense.
    Last edited by jbum; 03-08-2005 at 07:06 PM.

  8. #8
    ____________
    Join Date
    Sep 2004
    Location
    Hells Kitchen
    Posts
    191
    Actually I can't control the vars, they come from a DB I don't have access to. Anyways I descided to do the math with php and have it add two more vars to the bunch( high and low) that are brought into Flash. Ya got ta give Flash a break now and then.

    Thanks guys!
    _

    __________________

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