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)
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
timeKeeper.clearIntervalCall(intervalID:Number);
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.
MHU Package / Timer Class
if you have any question SHOOT!












1 response so far ↓
Fredrik // August 17, 2007 at 9:36 am |
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!
Fred