Reputation: 53
I need to call an object or function name with string variable.
For example;
var item_1:Object;
var str:String = "item_1";
TweenLite.to(item_1, 2, {alpha:0});
it's working but,
if I do something like below its not working
var item_1:Object;
var str:String = "item_1";
TweenLite.to(str, 2, {alpha:0});
how can do that? thanks from now..
Upvotes: 1
Views: 1685
Reputation: 25489
Try something like
this[str];
//or
root[str]
All objects in AS3 can be accessed as object[key]=value
So, if you know where item_1
is declared, you can call it as itemParent["item_1"]
or in your example, itemParent[str]
Upvotes: 3
Reputation: 10325
I'm having some trouble reading your question, but it seems like you're looking for the following:
var item_1:Object
var str:String = "item_1"
TweenLite.to(this[str], 2, {alpha:0});
To dynamically access objects by their id from a string, you need to use the this["itemid"]
notation.
Upvotes: 2