|
-
Senior Member
"string" to variable
Hello all!
I'm trying to use a string to determine a specific variable.
For example.
Code:
onClipEvent (load) {
var1 = "var2";
var2 = new Object();
var2.a = "no";
_root[var1].a = "yes";
}
Is this possible? I really do think it is. But I'm really not sure how to go about doing it. The main reason. I have to save/load hundreds of objects/variables. and in order to determine which ones to load, i wanted to make a variable to tell it which ones to load.
Basically, so I don't have to do this...
Code:
onClipEvent(load) {
if(var1 == "var2") {
_root.var2.a = "yes";
}
if(var1 == "var3") {
_root.var3.a = "yes";
}
if(var1 == "var4") {
_root.var4.a = "yes";
}
}
So yea, any help is appreciated,
Thanks!
~Bill
So many Ideas
So little Time
-
Flashmatics
not sure if i fully understand the question, but from what i do.. do u mean something along these lines?
Code:
for(var i:Number=0 ; i< 200; i++){
if(var1 == "var"+String(i)){
_root["var"+String(i)].a = "yes";
}
}
-
Senior Member
hmmm, not exactly. All I really need to know is how this...
_root[var1].a = "yes";
would compute to this....
_root.var2.a = "yes";
I havent been able to do it that way. unless its something else thats makeing it not work... So, does that seem like it should work?
At first I thought it didnt work because what flash is seeing is this...
_root."var2".a = "yes";
Which wouldnt make sense in actionscript. but yea. any thoughts?
~Bill
So many Ideas
So little Time
-
code:
var1 = "var2";
var2 = new Object();
var2.a = "no";
_root[var1].a = "yes";
trace(var2.a);
Works as expected for me...
K.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|