Function -> linking

i have many buttons, that do practicly the same, except with a different target. Therefore i want to give them a function.
So far the function is on the _root. and the buttons ask for it like:

[color=blue]_root.gonext(“zh”);[/color]

and the function on the root is:

[color=blue]function gonext(mc){[/color]
[color=blue]targett = “p_” + mc;[/color]
[color=blue]targett.gotoAndStop(“whatever”);[/color]
[color=blue]// plus a lot more[/color]
[color=blue]}[/color]

So the mc called ‘p_zh’ should gotoAndStop at “whatever”, but this doesnt work. AS reads the word targett as the target, not as a variable.

How do i let the function link back to the custom mc?

AS reads the targett as a string that has the name of the target, not the target itself. To make the name string a valid movieclip reference, you would need to use eval or array access brackets. ex:

targett = “p_” + mc; // as name
targett = root["p" + mc]; as a reference to the movieclip named “p_” + mc in _root.

ok
root["p" + mc].gotoAndStop(“over”);
worked.

no need for giving it a variable name now.

Thanks