Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with creating variable names

New Here ,
Jul 31, 2013 Jul 31, 2013

Hi, I'm having trouble with the following function:

private function whichLevelToLoad():void{

                              if(levelToLoad == "nothing"){

                                        currentLevel = null;

                                        }

                              var thisObj:Object = new Object();

                              if(levelBtnArray!=null){

                              for(var j:int=levelBtnArray.length-1;j>=0;j--) {

                                        if(levelToLoad == String("level " + (j+1))){

                                        thisObj["level"+(j+1)] = new ["Level"+(j+1)]();--------------------------->The Problem

                                        thisObj["level" + (j+1)].x = 0;

                                        thisObj["level" + (j+1)].y = 0;

                                        addChildAt(thisObj["level" + (j+1)], 0);

                                        currentLevel = thisObj["level" + (j+1)];

                                                  }

                                        }

                              }

                    }

I'm trying to instatiate 75 objects by using a loop. The line would look like this,"thisObj.level1 =  new Level1(); with the numbers going from 1-75. Is this possible? How

do I do it?

Thank you....

TOPICS
ActionScript
479
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Jul 31, 2013 Jul 31, 2013

getDefinitionByName solves this problem.

Example

Translate
Guru ,
Jul 31, 2013 Jul 31, 2013

getDefinitionByName solves this problem.

Example

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 31, 2013 Jul 31, 2013
LATEST

thanks a lot.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines