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

Posted on 2008-10-17
Medium Priority
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?
Question by:cakepizza
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4

Expert Comment

ID: 22741710
In a word, no.

What use could you possibly find for such a feature?

Expert Comment

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

Author Comment

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?

Accepted Solution

DigitalSnorkle earned 2000 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


Expert Comment

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

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
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.
Suggested Courses

771 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