Solved

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

Posted on 2008-10-17
5
172 Views
Last Modified: 2013-11-11
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
Comment
Question by:cakepizza
  • 4
5 Comments
 
LVL 3

Expert Comment

by:DigitalSnorkle
ID: 22741710
In a word, no.

What use could you possibly find for such a feature?
0
 
LVL 3

Expert Comment

by:DigitalSnorkle
ID: 22741798
You can store named references to an objects using associative arrays or dictionaries.
0
 

Author Comment

by:cakepizza
ID: 22742811
"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
 
LVL 3

Accepted Solution

by:
DigitalSnorkle earned 500 total points
ID: 22774912
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
 
LVL 3

Expert Comment

by:DigitalSnorkle
ID: 22774921
sorry, Line 3 shouldn't have var at the start.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question