tellTarget + duplicateMovieClip problem

+++ CASE +++
I’m doing a duplicateMovieClip and that works fine. But I can’t seem to trigger any actions like gotoAndPlay(nextFrame) in a duplicated mc from another duplicated mc… unless I hardcode a target.

+++ trial and error +++
if I prepare a string and use it as a target, it won’t work. If I hardcode it the tellTarget works fine. What am I doing wrong?

> WORKS:
str = “_root.system.menu.template2”;
tellTarget(str) { doSomething(); }

> DOES NOT WORK:
// textfield with one of the duplicated movieclip names
pmc = _root.system.menu.txt;
str = “_root.system.menu.” add pmc;
tellTarget(str) { doSomething(); }

> When I do a trace(str) on that string it seems to be correct. I’ve also tried using a valueOf() but that does not help me.

situation:
> A movieclip is duplicated (the original was named “template” and the duplicates get a number attached to that) there’s a button with a small script.
> In the movieclip that holds the duplicate mcs, I store a variable (txt) with the name of the movie clip where a button has last been clicked on. It has a value like “template1”.

Thanks a lot for the help!

*Originally posted by vermaha *
> DOES NOT WORK:
// textfield with one of the duplicated movieclip names
pmc = _root.system.menu.txt;
str = “_root.system.menu.” add pmc;
tellTarget(str) { doSomething(); }

Wait a second. If you trace str, there’s no way this can be correct.
str=_root.system.menu._root.system.menu.txt in your case…

pom :asian:

I might well omit the pmc var. I don’t think there’s something wrong with that?? _root.system.menu is not between quotes so it refers to the value in the dynamic textfield var called txt.

> pmc = _root.system.menu.txt;
trace(pmc);

then I get that value; for example “template1”

when I combine the two strings pmc + the rest into one new string. When I do a trace() of that new string I get this perfect result. That’s what I described in my first post.

> “_root.system.menu.template1”

There is no problem at all… but I can’t USE that result as a target… What’s wrong?

I don’t know what’s wrong. But I do know 2 things:

  • tellTarget sucks, go for the dot syntax
  • this works:
// Imagine that "template1 is contained inside the variable "path"
_root.system.menu[path]._x++;
// for instance

This will evaluate path all right. Careful, no . before the []. Tell me how this works.

pom :asian: