• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

is there a way to declare a new variable based on the value of another variable?

in action script 3.0 I want to declare a new variable based on the value of another variable.  For example if var MyVar1:String="Super";
Then I want it to create a new string variable with the name "Super".
Is there a way to have variable based variable names like this?
0
cakepizza
Asked:
cakepizza
  • 4
1 Solution
 
DigitalSnorkleCommented:
In a word, no.

What use could you possibly find for such a feature?
0
 
DigitalSnorkleCommented:
You can store named references to an objects using associative arrays or dictionaries.
0
 
cakepizzaAuthor Commented:
"You can store named references to an objects using associative arrays or dictionaries."

ok...so what would that look like.  Can you post some code showing me what you mean?
0
 
DigitalSnorkleCommented:
The example below uses a flash.utils.Dictionary

Line 1: Creates an object (the value) you'd like to store.

Line 2: Create a new, empty dictionary.

Line 3: Adds the value object to the dictionary associated with the keyword/name "frankthepotato"

Line 4: Extracts the value object, by calling the dictionary with the keyword as before.  myExampleObject2 is now equal to myExampleObject.

var myExampleObject:Potato = new Potato();
 
var myDictionary:Dictionary = new Dictionary();
 
var myDictionary["frankthepotato"] = myExampleObject;
 
var myExampleObject2:Potato = myDictionary["frankthepotato"];

Open in new window

0
 
DigitalSnorkleCommented:
sorry, Line 3 shouldn't have var at the start.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now