dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Using a variable for an instance name??

Hybrid View

  1. #1
    Member
    Join Date
    Jul 2004
    Location
    New Haven, CT
    Posts
    79

    Question Using a variable for an instance name??

    Ok, I've been at this for 2 days now, and really need some assistance. It seems like it should be so simple!

    The part that doesn't work:

    Code:
    on(release){
    	critter_pressed_new.gotoAndStop("poof");
    	// or this:
            [critter_pressed_new]gotoAndStop("poof");
    }
    Where, "critter_pressed_new" is not a specific instance name, but rather a variable name.

    Please see the attached file and take a look if you are familiar with variables.

    If you want more info, here's the deal...

    I randomly launch some movie clips from the library with attachMovie (they are bedbugs). No problem there.

    On launch they get instance names. The first one gets "critter_launched_01", the second "critter_launched_02".

    There is a button in the root that needs to be able to make the critter go away (by going to a frame label of "poof", which has a red X on it for now).

    I have a little test button that is hard-coded for:
    Code:
    on(release){
    	//this is what code needs to do from other button, but using var name:
    	_level0.critter_launched_01.gotoAndStop("poof");
    	_level0.critter_launched_02.gotoAndStop("poof");
    }
    and it works fine. No problem there.

    But, I need to be able to have one button close only the most recent bug. So I created a variable in the root to keep track of the last one out:

    Code:
    var critter_pressed_new = "test";
    Then within the critter mc I update it using this:
    Code:
    _root.critter_pressed_new = targetPath(this);
    which now makes the variable of "critter_pressed_new" have the instance name of the movie clip in it (which, would be _level0.critter_launched_01 or 02).

    Then that button in the root should be able to take the value that is in the variable "critter_pressed_new" and use that as the instance name, to make that particular mc go away.

    Please help if you can offer any advice at all!! Thank you!
    Attached Files Attached Files

  2. #2
    Member
    Join Date
    Jul 2004
    Location
    New Haven, CT
    Posts
    79
    OK found it!

    eval(critter_pressed_new).gotoAndStop("poof");

    Knew it would be something simple!

    But if anyone knows of a better way, please let me know. I recall seeing somewhere that eval() was deprecated.

  3. #3
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Eval has been depreciated, however as long as the code is written in AS2 or lower it should be fine.
    Wile E. Coyote - "Clear as mud?"

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