Skip to main content
Inspiring
June 10, 2011
Answered

Can you use a variable as the name of a variable like you can in Perl?

  • June 10, 2011
  • 1 reply
  • 461 views

So say there are 10 movieclips on the stage, each named mc1 mc2 mc3 etc. In a public class I have a function that sends the name of a movieclip and I need to be able to change the frame of that movieclip based on the string that is sent. So say my class function declaration is:

moveFrame(theMovieClip);

where theMovieClip is the returned object from another function.

Is there any way to use that variable somehow?

The concept of what I'm trying to do:

function moveFrame(s) {

    s.gotoAndStop("the right frame");

}

Does that make sense? Is it possible or do I need to find another workaround?

This topic has been closed for replies.
Correct answer Ned Murphy

If the function argument (s) points to the object, then your code as shown should work.

s.gotoAndStop("the right frame");

If the argument points to the name property of the object, then you would need to use the getChildByName() method to target the instance.

this.getChildByName(s).gotoAndStop("the right frame");

If the argument is a String version of the object's instance name, then you could use bracket notation to target the object...

this.gotoAndStop("the right frame");

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
June 10, 2011

If the function argument (s) points to the object, then your code as shown should work.

s.gotoAndStop("the right frame");

If the argument points to the name property of the object, then you would need to use the getChildByName() method to target the instance.

this.getChildByName(s).gotoAndStop("the right frame");

If the argument is a String version of the object's instance name, then you could use bracket notation to target the object...

this.gotoAndStop("the right frame");

AmbariAuthor
Inspiring
June 10, 2011

Thanks!!!

Ned Murphy
Legend
June 10, 2011

You're welcome