# changing the TIMER delay for each object added to stage

**URL:** <https://forum.kirupa.com/t/changing-the-timer-delay-for-each-object-added-to-stage/634765>\
**Category:** flash\
**Created:** [June 14, 2016, 10:01am UTC](https://forum.kirupa.com/t/changing-the-timer-delay-for-each-object-added-to-stage/634765 "2016-06-14T10:01:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tzvika\_Frenkel](https://avatars.discourse-cdn.com/v4/letter/t/ac91a4/32.png) [@Tzvika\_Frenkel](https://forum.kirupa.com/u/Tzvika_Frenkel)\
**Post date:** [June 14, 2016, 10:01am UTC](https://forum.kirupa.com/t/changing-the-timer-delay-for-each-object-added-to-stage/634765/1 "2016-06-14T10:01:34Z")

</div>

I am building a game in which I added enemies to the stage (using loop in the Main as file).

now i’m trying to make each enemy change state and move to the second frame (gotoAndStop(2)) after random delay time and I can’t make the delay change for each enemy.  
actually, I didn’t manage to change the delay time at all, although it seems in the trace that my variable changes.

this is the code:

package  
{  
import flash.display.MovieClip;  
import flash.events.Event;  
import flash.utils.Timer;  
import flash.events.TimerEvent;

```
public class BadGuys extends MovieClip
{
            private var randNum:Number = Math.round(Math.random() * 10);
	private var myTimer:Timer = new Timer(5000,1);
     }

public function BadGuys()
{			
	myTimer.addEventListener(TimerEvent.TIMER, changeEnemyState);
	myTimer.start();		
}

    private function changeEnemyState(Event:TimerEvent):void {
	randNum = Math.round(Math.random() * 10);
	myTimer.delay = randNum;
	this.gotoAndStop(2);
	}
```
