dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Select/Deselect with arrays

  1. #1
    Registered User
    Join Date
    Apr 2001
    Posts
    10

    Select/Deselect with arrays

    I've been working on a project for the past few days, and i've hit a major stumbling block. Here's the deal:

    I'm using buttons to duplicate movieclips, and storing their variable names in an array (ie: arrayname[x] = "item_" + x ). so the names are all catalogued by number.

    That goes off without a hitch. Now what I want to do is click on one and "select" it. this is being done by telling the duplicated movieclip to go to the second frame, where it turns grey. When one is selected i want to deselect all of the others. this is where i have a problem.

    inside the movieclip i have run through a while loop that looks like this:

    i=0;
    while (i < arrayname.length) {
    arrayname[i].gotoAndStop(1);
    i++
    }

    When i run this script absolutely nothing happens. I've done traces, and all the variables check out alright, but for some reason they won't target the item_1, item_2, etc.

    Can anyone think of why that might happen?
    Thanks lots.

  2. #2
    Member
    Join Date
    Jan 2003
    Location
    Australia, Adelaide (SA)
    Posts
    97
    Hi aaakpth,

    The problem is that your array contains the names of the movieclips, not references to them, you have two options as I see it:
    1) Change the array to hold the references instead of just the names
    2) Use the names to reference the movieclips

    Either way, you will need to reference them something like this:
    Code:
    // assuming your code is running on the parent MC
    // if you need to, replace 'this' with the name of the parent MC
    for( var i=0; i < arrayname.length; i++ )
    {
      this[ arrayname[i] ].gotoAndStop(1);
    }
    Hope this helps!

  3. #3
    Registered User
    Join Date
    Apr 2001
    Posts
    10
    dude it worked perfectly, thanks a hell of a lot!

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