Resolving dynamic movieclip names

Hello Kirupians…

I am trying to dynamically access a function belonging to a dynamically created movieclip instance. I actually got a majority of the code from a tutorial here on Kirupa (thank you very much), but there is one small thing I am trying to do and can’t quite figure out.

I really do not know the best way to describe my problem. I basically have some code which creates the path as a string (the variable “path”), but I cannot figure out how to resolve that string. I have tried using eval, but that is not it. I have tried splitting the path into diff chunks, but that has not worked either.

Basically I need to put a certain number of “.submenu” mclips into my path based on the value of another variable: lvl1cnt. As I mentioned above, the following code creates path correctly, but I can’t seem to figure out how to get Flash to execute the path string as a statement.

Any ideas? Have I given enough info??


for(var i=0; i<itemcnt; i++){
    path="_root.mmenu";
    for(var j=0;j<lvl1cnt;j++){
        path +=".submenu";
    }
    path+="[\"mitem\"+i].dorollover()";
    //eval doesnt work ;(
    eval(path);
}

Thanks,
tROCK

There are several variations you could use… try these two:

for (var i=0; i<itemcnt; i++) {
	path = "_root.mmenu";
	for (var j=0; j<lvl1cnt; j++) {
		path += ".submenu";
	}
	eval(path)["mitem"+i].dorollover();
}
//
for (var i=0; i<itemcnt; i++) {
	path = _root.mmenu;
	for (var j=0; j<lvl1cnt; j++) {
		path = path.submenu;
	}
	path["mitem"+i].dorollover();
}

Check out this thread, it might clear things up for you: http://www.kirupaforum.com/forums/showthread.php?t=12082#post85182.

FANTASTIC!!

I tried option 2 (just because I liked the way it looked) and it worked to perfection. Thanks alot KODE.

Once again, Kirupa.com to save the day. It is too easy to say this is the best Flash site out there… I think it is one of the best sites (across all genres) out there!

No problem, trock. :slight_smile:

…You’re definitely right about that! :stuck_out_tongue: