[AS3] Assigning different variables

Discussion in 'Programming' started by Miquexia, Mar 25, 2011.

  1. #1
    Hello,

    Is it possible to assign different names of variables each time a function is triggered?

    Since I've got a timer that triggers a functions, the function itself just adds a new object called "antwoorden" to the stage. Now, how can I let it add the new object with different kind of names, each time the function is called? For example, timer triggers for the first time: Adds "antwoordenOne" to the stage, timer triggers again: Adds "antwoordenTwo" to the stage. Again: "antwoordenThree", etc. That way I can give each object (of the same class) different kind of parameters.

    The code:

    
    timer = new Timer(4000, 6); // Timer gets triggered every 4 secs (6 times.)
    timer.start();
    timer.addEventListener(TimerEvent.TIMER, onTime);
    
    private function onTime(event:TimerEvent):void
    {
    	tekenAntwoord();
    }
    
    private function tekenAntwoord():void
    {
    	antwoorden = new Antwoorden();
    	antwoorden.x = Math.random()*(stageWidth - antwoorden.width);
    	addChild(antwoorden);
    }
    
    Code (markup):
    Anyone can help me out with this one?

    Greets.
     
    Miquexia, Mar 25, 2011 IP