How can I use the value of a variable to perform and action?

Example:
I set variable "Code" to "_root.gotoAndPlay(2);"

Code = _root.gotoAndPlay(2); //In root movie

I want a movie clip to use this value and the end of it's timeline. The reason I need to use the entire string is because it might not always be a gotoAndPlay action. It might be a loadMovie or something else. How can I call on this value to use it as an action later? I've been successful at using variables to insert values into actions, but can't figure out how to use the values as the full actions.

Thanks in advance,

Scott