Reputation: 5029
So, if I need to give a custom variable name to an object how would I do that?
For instance, if I have a gameID that is 12345 and its rating is 3 I want to save a variable called gameRatings_12345 thats value is 3 in my shared local object.
//share object
protected var mySavedData:SharedObject = SharedObject.getLocal("mySavedData");
I have the game id in a string
var gameID:String = "12345";
Then when I try to assign the value like this...
mySavedData.data.gameRatings_gameID = 3
I think it's literally reading it as "mySavedData.data.gameRatings_gameID"
instead of "mySavedData.data.gameRatings_12345"
How can I give the variable a custom name?
Upvotes: 1
Views: 2835
Reputation: 4785
You can use [] notation for setting properties which are dynamically created at runtime.
In your example I think you'd use:
mySavedData.data["gameRatings_" + gameID] = 3;
Upvotes: 4