dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Retrieving objects in an array

  1. #1
    Has Returned
    Join Date
    Mar 2001
    Posts
    269

    Retrieving objects in an array

    Okay i have an array storing what i have found out to be objects.
    Is there anyway i can return the value of Score or Player from the array?

    Code:
    wormscores = new Array();
    wormscores.push({Player:"Unknown", Score:10});
    TIA,
    Turbs

  2. #2
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Hi,

    Yes use: wormscores[i].Player and wormscores[i].Score (where "i" is the array member id -number- Is zero based: 1st element is your wormscores[0])

    Example:
    PHP Code:
    wormscores = new Array();
    wormscores.push({Player:"Unknown"Score:10});
    wormscores.push({Player:"Unknown2"Score:15});

    var 
    Player
    var Score

    for (a=0;a<wormscores.length;a++){
        
    Player=wormscores[a].Player
        Score
    =wormscores[a].Score
        trace
    (Player+":  "+Score)

    Kostas
    K. Zotos online portfolio: http://www.in3d.eu

  3. #3
    Has Returned
    Join Date
    Mar 2001
    Posts
    269
    Thanks for that.

    Saved me lots of time. Trying to make a quick scoreboard for an old snake game i made ages ago.

  4. #4
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Don't mention it!

    Quote Originally Posted by Turbs
    Trying to make a quick scoreboard for an old snake game i made ages ago.
    Sounds interesting..

    Good luck with it!
    K. Zotos online portfolio: http://www.in3d.eu

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