Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Find the value of a variable when variable name is a string

Question posted by: Unicron (Newbie) on May 7th, 2008 04:48 PM
Hey folks. I have searched high and low for the answer to what seems to be a simple problem. Perhaps I don't know how to describe the title properly so if this has been dealt with before, please forgive me.

I would be glad to take an answer for this in Actionscript, Javascript, or PHP. (because I have run into the problem in all 3 scripting langs.)

Color1 = "red"
Color2 = "blue"
Color3 = "green"

function showColor(num) {

.... help here
}

The function passes a number only. I want to use showColor(1) to print "red" but can't figure it out.

The only things I can ever get are undefined variables or the word "Color1".
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
jitu78's Avatar
jitu78
Newbie
30 Posts
May 11th, 2008
04:25 PM
#2

Re: Find the value of a variable when variable name is a string
Quote:
Originally Posted by Unicron
Hey folks. I have searched high and low for the answer to what seems to be a simple problem. Perhaps I don't know how to describe the title properly so if this has been dealt with before, please forgive me.

I would be glad to take an answer for this in Actionscript, Javascript, or PHP. (because I have run into the problem in all 3 scripting langs.)

Color1 = "red"
Color2 = "blue"
Color3 = "green"

function showColor(num) {

.... help here
}

The function passes a number only. I want to use showColor(1) to print "red" but can't figure it out.

The only things I can ever get are undefined variables or the word "Color1".


=================
Code: ( text )
  1. var col:string;
  2.  
  3. function showColor(num) {
  4. if (num==1)
  5. {col="red";}
  6. else
  7. if (mun==2)
  8. {col="blue";}
  9. else
  10. {col="green";}
  11. trace(col);
  12. }



- Jitendra

Reply
Reply
Not the answer you were looking for? Post your question . . .
182,248 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Flash / Actionscript Forum Contributors