I personally use an extremely simplified way of dealing with events.
I've used EventDispatcher before, but it feels like overkill most of
the time. I realize my method has no ability to multicast events,
but it's quick, easy to read and gets the job done.
Here's an example:
___________________________
// WidgetManager.as
import mx.utils.Delegate;
class WidgetManager {
private var _widget1:Widget;
private var _widget2:Widget;
public function WidgetManager (timeline:MovieClip) {
_widget1 = new Widget(1, timeline.widget1_mc);
_widget1.clickEvent = Delegate.create(this, widgetClick); //
add event
_widget2 = new Widget(2, timeline.widget2_mc);
_widget2.clickEvent = Delegate.create(this, widgetClick); //
add event
}
private function widgetClick (eventObj:Object):Void {
trace("widget " + eventObj.id + " was clicked");
eventObj.target.clickEvent = null; // remove event
}
}
___________________________
// Widget.as
import mx.utils.Delegate;
class Widget {
public var clickEvent:Function; // event method
private var _id:Number;
private var _buttonMC:MovieClip;
public function Widget (id:Number, mc:MovieClip) {
_id = id;
_buttonMC = mc;
_buttonMC.onPress = Delegate.create(this, buttonPress);
}
public function buttonPress ():Void {
clickEvent({target:this, id: _id});
}
}
On Sep 26, 2006, at 12:09 PM, Sean Scott wrote:
Hi All!,
wondering if someone can point me in the right direction. I am trying
to find a ASBoradcast / Event Dispatcher light model for my app.
Basically i have a number of MCs that will have to either react to
events being broadcast or broadcast their own.
I have Essential AS2 by Colin Moock. Trying to find something i can
import and maybe pass scope to it, vs have my main class extend it.
I've googled, searched the archived and exausted my more talented
flash developer friends.
Thanks,
Sean
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com