Two days ago I decided to try out haXe, an AS3 type of language that can compile code to various formats, SWF, PHP, C++ among others.
I thought it would be good to try some other language than good old PHP or actionscript. Although haXe and Actionscript are closely related, there are several differences. haXe offers some very nice language elements, which make it better in than actionscript in a lot of respects. First of all types are a bit different and haXe has stronger type enforcing, for function types for example.
I was missing the good old actionscript eventlisteners and timer implementation. I managed to write a few classes to implement basic event handlers. No event bubbling, no canceling of propagation, but apart from that fully functional dispatchers and listeners.
For the timer, just use it more or less like an as3 timer as in the example below (note no TimerEvents).
var timer:HaxeTimer = new HaxeTimer(100, 10);
timer.addEventListener(new HaxeEvent(HaxeEvent.TIMER), timerHandler);
function timerHandler(e:HaxeEvent):Void{
trace(e.target.currentCount);
// DoStuff
}
You can find a link to the package below. The code is now in no way optimized for dispatchers with listeners for many different events. I think the listeners should be placed in different arrays according to event type, to make notifying quicker.
Download the events package
Please let me know if you have any code suggestions or if you spot any bugs.