Skip navigation
anjemalo
Currently Being Moderated

Get value of a variable

Dec 11, 2011 3:36 AM

Hello:

In other language I can use this kind of sentences:

 

function DoSomething (n:uint):void

{

   

    var Myvalue:Object;

    Myvalue="image"+n+"_mc");

    Myvalue.gotoAndPlay(2);

}

 

How can achieve this? because the above code does not work.

Many thanks

 
Replies
  • Currently Being Moderated
    Dec 11, 2011 4:39 AM   in reply to anjemalo

    You have an unmatched closing parenthesis so that will not work, but to use a String to target an object you can use the bracket notation...

     

    this["image"+n+"_mc"].gotoAndPlay(2);

     

    I show it without the variable since that is an unnecessary step, though you can use it if you prefer.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points