Callbackdispatcher

A few posts ago I talked about referencing the current class to solve the scope problem when using events in Flash.

Another (better) way to solve this problem is using de EventDispatcher class made by Moses Gunesch [www.mosessupposes.com]. The class makes it easy to scope all automatic callbacks in simple movieclips, buttons, or textfields,when you really need to get the events in the scope you’re in. For instance if the class you’re writing creates a bunch of buttons and needs to handle their events, you can just initialize them and add event listeners to them.You can download the files (with examples) here: callbackdispatcher

Methods:
--------------
CallbackDispatcher.initialize(targetObj);
targetObj.addEventListener (event:String,handler)
targetObj.removeEventListener (event:String,handler)
targetObj.addEventListeners (events:Array,handler)
targetObj.removeEventListeners (events:Array,handler)

Sample Usage:
-------------------------
var d:Object = mx.utils.Delegate.create(this, handleNavItemEvent);
for (var i=0; i<5; i++) {
var mc:MovieClip = scope.attachMovie('navItem', 'item'+i, i, {id:i});
CallbackDispatcher.initialize(mc);
mc.addEventListeners (['onRollOver','onRollOut', 'onRelease'], d);
}

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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