dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: bl00dy Math.min

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Location
    Reading, UK
    Posts
    149

    bl00dy Math.min

    Hello.

    I am trying to get Flash 5 to return the lowest variable from an array.

    Here's my code:



    for (ld=0; ld<=freePlayers.length; ld++) {

    dd = freePlayers[ld].distance;

    shortest = Math.min (dd, shortest);
    }


    When I run it, Flash claims that dd is "undefined"

    Why?

  2. #2
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    Is variable "distance" defined in the objects stored in the array freePlayers?

  3. #3
    Senior Member
    Join Date
    Jul 2003
    Location
    Reading, UK
    Posts
    149
    Thanks for replying. I have fixed that error now.

    I should have had "freePlayers.length-1" in the 'for' loop.

    With "freePlayers.length", the loop attempts to check an object which does not exist, so returns "dd" as undefined.

    DjRubbish

  4. #4
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    ..or you could just remove the = in the comparison:
    code:
    ld < freePlayers.length


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