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).
|
|
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 )
var col:string; function showColor(num) { if (num==1) {col="red";} else if (mun==2) {col="blue";} else {col="green";} trace(col); }
- Jitendra
 |
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
|