Actionscript 2, Actionscript 2.0, Flash, Flash _, Web developer

Custom setInterval replacement class – Timer from Misuta Hagane Util package

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

MHU Package / Timer Class

initializing the class

– place com.hagane.MHU folder in root of your project
– import in flash project via AS

import com.hagane.MHU.Timer;

– create instance of the class

var timeKeeper : Timer = new Timer();

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

var mc:MovieClip = _root.createEmptyMovieClip(“mc”, 50);
var timeKeeper : Timer = new Timer(mc);

add interval function call

var intervalID_mc : Number = timeKeeper.intervalCall(time:Number, repeat:Number, func:Function, param: Parameters…);

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

function returns ID of your interval, which you will later use to clear interval

for example

var intervalID_num : Number = timeKeeper.intervalCall(999, 5, traceABC, 3, 5, 6, “myInterval”);

clearing interval


In archive file you have everything set up for testing.
You will see main action is taking place in which is included in first frame of FLA file.
MHU Package / Timer Class

if you have any question SHOOT!


3 thoughts on “Custom setInterval replacement class – Timer from Misuta Hagane Util package

  1. Hey man!

    Great work. Had also experienced some problems with setInterval and mainly with clearInterval, hope this works better. I´m using this inside a class extending MovieClip so i´ve added the delegate when it comes to declaring the function, otherwise it didn´t work.

    roundTimeKeeper = timeKeeper.intervalCall(1000, -1, Delegate.create(this, roundTimer));

    Let you know how it works out for me.
    Thanks again!


  2. Great post. I was checking constantly this blog and
    I am impressed! Extremely useful info specially the
    last part 🙂 I care for such information much.
    I was looking for this certain info for a long time.
    Thank you and good luck.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s