# Incorporating random func with a Time class: Help?

**URL:** <https://forum.kirupa.com/t/incorporating-random-func-with-a-time-class-help/249359>\
**Category:** flash\
**Created:** [January 17, 2008, 10:24pm UTC](https://forum.kirupa.com/t/incorporating-random-func-with-a-time-class-help/249359 "2008-01-17T22:24:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mawhonic](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@Mawhonic](https://forum.kirupa.com/u/Mawhonic)\
**Post date:** [January 17, 2008, 10:24pm UTC](https://forum.kirupa.com/t/incorporating-random-func-with-a-time-class-help/249359/1 "2008-01-17T22:24:26Z")

</div>

Well, I’m in the drudgingly slow process of creating a game as so many of us are here on this forum, and as luck would have it I’ve ran into a notorious snag in my programming.

Alright, in my game I was trying to have an enemy character randomly decide upon one of a set of actions that could be possible to inact given the ActionScript 3 random function. And that works all well and good but it only does it once when the game is started. So, my friend said there was a Timer Class which gives the programmer the ability to run any set of code over the time period of the interaction. So, I thought I’d have this time class run this random function every second that the game is being played and therefore the enemy fighter would continuously inact a random action while its not destroyed, of course.

Welp, if there is a better way to accomplish what I’m trying them I’m all ears, but below is presently the code that I have for the Time Class with the random function incorporated in it as well as the output including errors. I just can’t get the darn thing to work! Thanks again for suggestions.

CODE:

package  
{

```
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;

public var n:Number;
public var i:Number;
public var randomNum:Number;

public class TimerExample extends MovieClip 
{
	
	
	
    public function TimerExample() 
	{
        var myTimer:Timer = new Timer(1000);
        myTimer.addEventListener("timer", timerHandler);
        myTimer.start();
    }

    public function timerHandler(event:TimerEvent):void 
	{
		randRangeGen(1, 12);
		
		for (i = 0; i &lt; 1; i++) 
		{
		n = randRangeGen(1, 12);
		trace(n);
		}
	}
		
	public function randRangeGen(min:Number, max:Number):Number 
	{
		randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
		return randomNum;
		//trace("Working?" + randomNum);
		
				
	}
	
	/*public function randRange(event:Event):void
	{
		for (i = 0; i &lt; 1; i++) 
		{
		n = randRangeGen(1, 12);
		trace(n);
		}
	}*/
	
		
		    	//trace("timerHandler: " + event);
}

```

}

///////////////////////////////////////////////////////////////////////////////////////////////////////

OUTPUT: 1180: Call to a possibly undefined method addFrameScript Source: package
