# Custom setInterval replacement class - Timer from Misuta Hagane Util package

**URL:** <https://forum.kirupa.com/t/custom-setinterval-replacement-class-timer-from-misuta-hagane-util-package/235719>\
**Category:** open source\
**Created:** [August 14, 2007, 7:07am UTC](https://forum.kirupa.com/t/custom-setinterval-replacement-class-timer-from-misuta-hagane-util-package/235719 "2007-08-14T07:07:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gvozden](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gvozden/32/1084_2.png) [@gvozden](https://forum.kirupa.com/u/gvozden)\
**Post date:** [August 14, 2007, 7:07am UTC](https://forum.kirupa.com/t/custom-setinterval-replacement-class-timer-from-misuta-hagane-util-package/235719/1 "2007-08-14T07:07:46Z")

</div>

need for replacemenr of setInterval in AS2.0 is obvious, it happened to me and to other people many times that clearInterval just won’t work… it’s basiclly in only 1% of cases but it’s enough  
so to help me and my friends I’ve created Timer class which fits into Misuta Hagane Utils package, which will soon get extension with some other interesting things (Misuta Hagane is my alias in Japanese language // my new homepage [http://hagane.us](http://hagane.us/))

blog post : [http://mrsteel.wordpress.com/2007/08/14/custom-setinterval-replacement-class-timer-from-misuta-hagane-util-package/](http://mrsteel.wordpress.com/2007/08/14/custom-setinterval-replacement-class-timer-from-misuta-hagane-util-package/)

[URL=“[http://www.hagane.us/as/MHU/MisutaHaganeTimer\_packageMHU.rar](http://www.hagane.us/as/MHU/MisutaHaganeTimer_packageMHU.rar)”]MHU Package / Timer Class

**initializing the class**

- place com.hagane.MHU folder in root of your project
- import in flash project via AS[INDENT]_import com.hagane.MHU.Timer; \*  
[/INDENT]- create instance of the class[INDENT]_ var timeKeeper : Timer = new Timer();\*  
[/INDENT]being that my class creates movieclip for enterframe events, by default it’s 32760 and it’s created in root and named timer, I made it possible that you tell in constructor what mc to use for timer  
In that case you create instance like this[INDENT]_var mc:MovieClip = \_root.createEmptyMovieClip(”mc”, 50);  
var timeKeeper : Timer = new Timer(mc);_  
[/INDENT]\*\* add interval function call\*\*[INDENT]_var intervalID\_mc : Number = timeKeeper.intervalCall(time:Number, repeat:Number, func:Function, param: Parameters…);_  
[/INDENT][INDENT] _time_:Number - time in ms  
\*repeat \*: Number - number of repeating, 0 and 1 for once, -1 for infinite  
\*func \*: Function - function to call  
\*param \*: Parameters - can be anything that fits into parameters of func - function you decided to call  
[/INDENT]function returns ID of your interval, which you will later use to clear interval  
for example[INDENT]_var intervalID\_num : Number = timeKeeper.intervalCall(999, 5, traceABC, 3, 5, 6, “myInterval”);_  
[/INDENT] **clearing interval** [INDENT]_timeKeeper.clearIntervalCall(intervalID:Number);_  
[/INDENT]In archive file you have everything set up for testing.  
You will see main action is taking place in main.as which is included in first frame of FLA file.  
[URL=“[http://www.hagane.us/as/MHU/MisutaHaganeTimer\_packageMHU.rar](http://www.hagane.us/as/MHU/MisutaHaganeTimer_packageMHU.rar)”]MHU Package / Timer Class

if you have any question SHOOT!  
[URL=“[http://www.hagane.us/as/MHU/MisutaHaganeTimer\_packageMHU.rar](http://www.hagane.us/as/MHU/MisutaHaganeTimer_packageMHU.rar)”]
