Skip to main content
Known Participant
July 31, 2013
Answered

Problem with creating variable names

  • July 31, 2013
  • 1 reply
  • 514 views

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....

This topic has been closed for replies.
Correct answer moccamaximum

getDefinitionByName solves this problem.

Example

1 reply

moccamaximumCorrect answer
Inspiring
July 31, 2013

getDefinitionByName solves this problem.

Example

Known Participant
July 31, 2013

thanks a lot.