FMS Event Dispatcher
I had an EventDispatcher class for fms a while ago. I updated it to be more similar to the EventDispatcher class in ActionScript3.
So, here it is for you to use it. If you find smth wrong plz let me know about it and i will be sure to post a fix asap.
BTW, this code is based on Adobe’s class and requires my __package and __import util methods.
- var p = __package("com.funciton.fms.events");
- p.EventDispatcher = function(){
- }
- var o = p.EventDispatcher.prototype;
- o.__listeners__ = new Object();
- o.__ID__ = 0;
- o.addEventListener = function(type, func){
- func.__ID__ = this.__ID__++;
- if(!this.__listeners__[type]) this.__listeners__[type] = new Array();
- this.__listeners__[type].push(func);
- }
- o.removeEventListener = function(type, func){
- if(func.__ID__ == null || !this.__listeners__[type]) return;
- var l = this.__listeners__[type].length;
- for(var i=0;i<l;i++){
- if(this.__listeners__[type][i].__ID__ == func.__ID__){
- var first = (i) ? this.__listeners__[type].slice(0, (i-1)): new Array();
- var last = (i < (l-1)) ? this.__listeners__[type].slice((i + 1)): new Array();
- this.__listeners__[type] = first.concat(last);
- break;
- }
- }
- }
- o.dispatchEvent = function(event){
- if(!this.__listeners__[event.type]) return;
- for(var i=0;i<this.__listeners__[event.type].length;i++){
- this.__listeners__[event.type][i].apply(this.__listeners__[event.type][i], event.__ARGS__);
- }
- }
- o.hasEventListeners = function(type){
- return !(!this.__listeners__[type] || !this.__listeners__[type].length);
- }
— fernando
webolius
Uds. si son de Perú pq no escriben artículos en español si es lo que más se necesita