Re: [Flashcoders] Delegating Events and AS2
Thanks all for the feedback. I ended up using Joey Lott's Proxy class. On 9/26/06, vic [EMAIL PROTECTED] wrote: Danno, that is really cool, I will try that but I have done it, I made a site template that, when a button is clicked it dispatches an Event...but I had the hardest time doing it. I am looking for a simple way to do it that works in a Class. without worrying about scope. Mine relies heavily upon scope. Anyone have any example? Thanks, V -- Original Message -- From: Dan Rogers [EMAIL PROTECTED] Reply-To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Date: Tue, 26 Sep 2006 20:55:32 -0700 Vic, if you've ever used the XML or NetStream classes... it mimics those types of event updates. For example... var xmlData = new XML(); xmlData.onLoad = function () { // gets invoked by the XML instance } So if you delegate the onLoad method, you get something like this: xmlData.onLoad = Delegate.create(this, xmlDataLoad); ... which is essentially what I am trying to do with my own classes. Another reason I like delegating events this way, is that the compiler will catch typos in the names of the event functions, so I am not searching around trying to figure out why a certain event is not firing. -Danro On Sep 26, 2006, at 7:06 PM, vic wrote: Hey Dan, I like the way you do it, its pretty simple. But here is, what probably will be an incredibly stupid question: How do I capture the event? Thanks, V 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 ___ 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 ___ 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
Re: [Flashcoders] Delegating Events and AS2
I think Delegate gives you what you're talking about Vic - control over your scope issues. Delegate enables you to manage scope with in your class. So, if you have an XML object and you want to maintain the response/return in your class, you do just as Dan has described. make sense? On 9/27/06, vic [EMAIL PROTECTED] wrote: Danno, that is really cool, I will try that but I have done it, I made a site template that, when a button is clicked it dispatches an Event...but I had the hardest time doing it. I am looking for a simple way to do it that works in a Class. without worrying about scope. Mine relies heavily upon scope. Anyone have any example? Thanks, V -- Original Message -- From: Dan Rogers [EMAIL PROTECTED] Reply-To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Date: Tue, 26 Sep 2006 20:55:32 -0700 Vic, if you've ever used the XML or NetStream classes... it mimics those types of event updates. For example... var xmlData = new XML(); xmlData.onLoad = function () { // gets invoked by the XML instance } So if you delegate the onLoad method, you get something like this: xmlData.onLoad = Delegate.create(this, xmlDataLoad); ... which is essentially what I am trying to do with my own classes. Another reason I like delegating events this way, is that the compiler will catch typos in the names of the event functions, so I am not searching around trying to figure out why a certain event is not firing. -Danro On Sep 26, 2006, at 7:06 PM, vic wrote: Hey Dan, I like the way you do it, its pretty simple. But here is, what probably will be an incredibly stupid question: How do I capture the event? Thanks, V 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 ___ 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
Re: [Flashcoders] Delegating Events and AS2
John, I think so but what I am trying to do it set up a BtnFunc Class that I can pass an argument to in order to set up the functionality of the button (argument bein the button instance name). I am pretty close I have this so far: FLA (with btnOnStage on stage): import mx.utils.Delegate; function handleEvent(eventObj) { trace('handleConstruct') trace(eventObj.target); trace(eventObj.type); trace(eventObj.message); trace(eventObj.time); } var myBtnClass = new BtnFunc(0, btnOnStage); myBtnClass.addEventListener('click', Delegate.create(this, handleEvent)); -- Class (BtnFunc.as): import mx.events.EventDispatcher; import mx.utils.Delegate; class BtnFunc { var addEventListener:Function; var removeEventListener:Function; var dispatchEvent:Function; function BtnFunc(id, btn) { EventDispatcher.initialize(this); btn.onRelease = function() { trace('dispatching event'); dispatchEvent({type:'click', target:this, message:btn+' was clicked'}); }; } } It is firing off the event perfectly but my listener is not getting it and thus not running the handleEvent func. What's the prob? var myClass = new Timer(1000); myClass.addEventListener('timeout', Delegate.create(this, handleConstruct)); - Original Message - From: John Grden [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Wednesday, September 27, 2006 8:13 AM Subject: Re: [Flashcoders] Delegating Events and AS2 I think Delegate gives you what you're talking about Vic - control over your scope issues. Delegate enables you to manage scope with in your class. So, if you have an XML object and you want to maintain the response/return in your class, you do just as Dan has described. make sense? On 9/27/06, vic [EMAIL PROTECTED] wrote: Danno, that is really cool, I will try that but I have done it, I made a site template that, when a button is clicked it dispatches an Event...but I had the hardest time doing it. I am looking for a simple way to do it that works in a Class. without worrying about scope. Mine relies heavily upon scope. Anyone have any example? Thanks, V -- Original Message -- From: Dan Rogers [EMAIL PROTECTED] Reply-To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Date: Tue, 26 Sep 2006 20:55:32 -0700 Vic, if you've ever used the XML or NetStream classes... it mimics those types of event updates. For example... var xmlData = new XML(); xmlData.onLoad = function () { // gets invoked by the XML instance } So if you delegate the onLoad method, you get something like this: xmlData.onLoad = Delegate.create(this, xmlDataLoad); ... which is essentially what I am trying to do with my own classes. Another reason I like delegating events this way, is that the compiler will catch typos in the names of the event functions, so I am not searching around trying to figure out why a certain event is not firing. -Danro On Sep 26, 2006, at 7:06 PM, vic wrote: Hey Dan, I like the way you do it, its pretty simple. But here is, what probably will be an incredibly stupid question: How do I capture the event? Thanks, V 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
Re: [Flashcoders] Delegating Events and AS2
I'm not totaly sure, but you don't have to specify target - that's something that Delegate already adds to the event object it passes along On 9/27/06, vic [EMAIL PROTECTED] wrote: John, I think so but what I am trying to do it set up a BtnFunc Class that I can pass an argument to in order to set up the functionality of the button (argument bein the button instance name). I am pretty close I have this so far: FLA (with btnOnStage on stage): import mx.utils.Delegate; function handleEvent(eventObj) { trace('handleConstruct') trace(eventObj.target); trace(eventObj.type); trace(eventObj.message); trace(eventObj.time); } var myBtnClass = new BtnFunc(0, btnOnStage); myBtnClass.addEventListener('click', Delegate.create(this, handleEvent)); -- Class (BtnFunc.as): import mx.events.EventDispatcher; import mx.utils.Delegate; class BtnFunc { var addEventListener:Function; var removeEventListener:Function; var dispatchEvent:Function; function BtnFunc(id, btn) { EventDispatcher.initialize(this); btn.onRelease = function() { trace('dispatching event'); dispatchEvent({type:'click', target:this, message:btn+' was clicked'}); }; } } It is firing off the event perfectly but my listener is not getting it and thus not running the handleEvent func. What's the prob? var myClass = new Timer(1000); myClass.addEventListener('timeout', Delegate.create(this, handleConstruct)); - Original Message - From: John Grden [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Wednesday, September 27, 2006 8:13 AM Subject: Re: [Flashcoders] Delegating Events and AS2 I think Delegate gives you what you're talking about Vic - control over your scope issues. Delegate enables you to manage scope with in your class. So, if you have an XML object and you want to maintain the response/return in your class, you do just as Dan has described. make sense? On 9/27/06, vic [EMAIL PROTECTED] wrote: Danno, that is really cool, I will try that but I have done it, I made a site template that, when a button is clicked it dispatches an Event...but I had the hardest time doing it. I am looking for a simple way to do it that works in a Class. without worrying about scope. Mine relies heavily upon scope. Anyone have any example? Thanks, V -- Original Message -- From: Dan Rogers [EMAIL PROTECTED] Reply-To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Date: Tue, 26 Sep 2006 20:55:32 -0700 Vic, if you've ever used the XML or NetStream classes... it mimics those types of event updates. For example... var xmlData = new XML(); xmlData.onLoad = function () { // gets invoked by the XML instance } So if you delegate the onLoad method, you get something like this: xmlData.onLoad = Delegate.create(this, xmlDataLoad); ... which is essentially what I am trying to do with my own classes. Another reason I like delegating events this way, is that the compiler will catch typos in the names of the event functions, so I am not searching around trying to figure out why a certain event is not firing. -Danro On Sep 26, 2006, at 7:06 PM, vic wrote: Hey Dan, I like the way you do it, its pretty simple. But here is, what probably will be an incredibly stupid question: How do I capture the event? Thanks, V 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
Re: [Flashcoders] Delegating Events and AS2
The problem is with this code- the onRelease function is a method of the btn movieclip... so it doesn't have access to the dispatchEvent function. btn.onRelease = function() { trace('dispatching event'); dispatchEvent({type:'click', target:this, message:btn+' was clicked'}); }; You could just do something like this instead if you want a quick local function: var btnRelease = function () { dispatchEvent({type:'click', target:this, message:btn+' was clicked'}); } btn.onRelease = Delegate.create(this, btnRelease); Delegate saves the day again... -Danro On Sep 27, 2006, at 8:30 AM, vic wrote: John, I think so but what I am trying to do it set up a BtnFunc Class that I can pass an argument to in order to set up the functionality of the button (argument bein the button instance name). I am pretty close I have this so far: FLA (with btnOnStage on stage): import mx.utils.Delegate; function handleEvent(eventObj) { trace('handleConstruct') trace(eventObj.target); trace(eventObj.type); trace(eventObj.message); trace(eventObj.time); } var myBtnClass = new BtnFunc(0, btnOnStage); myBtnClass.addEventListener('click', Delegate.create(this, handleEvent)); -- Class (BtnFunc.as): import mx.events.EventDispatcher; import mx.utils.Delegate; class BtnFunc { var addEventListener:Function; var removeEventListener:Function; var dispatchEvent:Function; function BtnFunc(id, btn) { EventDispatcher.initialize(this); btn.onRelease = function() { trace('dispatching event'); dispatchEvent({type:'click', target:this, message:btn+' was clicked'}); }; } } It is firing off the event perfectly but my listener is not getting it and thus not running the handleEvent func. What's the prob? ___ 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
Re: [Flashcoders] Delegating Events and AS2
I have been using this class for all my event needs. Simply import the class, then to use: EventManager.getInstance().addListener(eventDoThis, this); //adds the listener to the class ('this' is the scope) EventManager.getInstance().removeListener(eventDoThis, this); //removes the listener EventManager.getInstance().dispatch({type: eventDoThis, param:true, param2:false, param3:etc}); //sends the event with params private function eventDoThis(eventObj:Object):Void { trace(eventDoThis called); var p1:Boolean = eventObj.param; var p2:Boolean = eventObj.param2; var p3:String = eventObj.param3; } For me, this setup is nice and clean to use. Just be sure to keep it as a Singleton to prevent additional EventManagers from overriding this one. ***CODE* //EventManager.as import com.core.events.*; class com.core.events.EventManager { private var eventListeners:Object = new Object(); private static var _instance:EventManager; private function EventManager(Void){} public static function getInstance(Void):EventManager { if(_instance === undefined){ _instance = new EventManager(); } return _instance; } //dispatch broadcasts the event to all who are setup as listeners public function dispatch(eventObject) { var tmpA:Array = eventListeners[eventObject.type]; // Loop through this way to avoid problems with adding/removing listeners during the dispatch for (var i in tmpA) { tmpA[i][eventObject.type](eventObject); } } //add a listener to the queue, this will get called once a dispatch event happens that matches public function addListener(event:String, listener:Object) { if (eventListeners[event] == undefined) { eventListeners[event] = new Array(); } removeListener(event, listener); // a listener should only listen to an event once eventListeners[event].push(listener); } //remove the listener from the queue, this prevents additional rebroadcasting. public function removeListener(event:String, listener:Object) { var tmpA:Array = eventListeners[event]; var len:Number = tmpA.length; for (var i:Number = 0; ilen; i++) { if (tmpA[i] == listener) { tmpA.splice(i, 1); return; } } } } ***END CODE* I hope this helps you out, let me know if you have any problems with it or have any additional questions. Steve -Original Message- From: [EMAIL PROTECTED] [mailto: [EMAIL PROTECTED] On Behalf Of Sean Scott Sent: Tuesday, September 26, 2006 2:09 PM To: Flashcoders@chattyfig.figleaf.com Subject: [Flashcoders] Delegating Events and AS2 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
RE: [Flashcoders] Delegating Events and AS2
Whoops! -Original Message- From: [EMAIL PROTECTED] [mailto:flashcoders- [EMAIL PROTECTED] On Behalf Of Mike Keesey Sent: Tuesday, September 26, 2006 2:23 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Delegating Events and AS2 [...] Or, if using AS3.0, I think you can wrap a flash.events.EventDispatcher object (Decorator Design Pattern): [...] private function _dispatcher:EventDispatcher; } Obviously, that should be: private var _dispatcher:EventDispatcher; ― Mike Keesey (Note: I haven't actually tried AS3.0, so someone let me know if I messed anything up.) ― Mike Keesey -Original Message- From: [EMAIL PROTECTED] [mailto:flashcoders- [EMAIL PROTECTED] On Behalf Of Sean Scott Sent: Tuesday, September 26, 2006 12:09 PM To: Flashcoders@chattyfig.figleaf.com Subject: [Flashcoders] Delegating Events and AS2 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 ___ 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
Re: [Flashcoders] Delegating Events and AS2
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
Re: [Flashcoders] Delegating Events and AS2
Hey Dan, I like the way you do it, its pretty simple. But here is, what probably will be an incredibly stupid question: How do I capture the event? Thanks, V 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 ___ 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
Re: [Flashcoders] Delegating Events and AS2
Vic, if you've ever used the XML or NetStream classes... it mimics those types of event updates. For example... var xmlData = new XML(); xmlData.onLoad = function () { // gets invoked by the XML instance } So if you delegate the onLoad method, you get something like this: xmlData.onLoad = Delegate.create(this, xmlDataLoad); ... which is essentially what I am trying to do with my own classes. Another reason I like delegating events this way, is that the compiler will catch typos in the names of the event functions, so I am not searching around trying to figure out why a certain event is not firing. -Danro On Sep 26, 2006, at 7:06 PM, vic wrote: Hey Dan, I like the way you do it, its pretty simple. But here is, what probably will be an incredibly stupid question: How do I capture the event? Thanks, V 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 ___ 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
Re: [Flashcoders] Delegating Events and AS2
Danno, that is really cool, I will try that but I have done it, I made a site template that, when a button is clicked it dispatches an Event...but I had the hardest time doing it. I am looking for a simple way to do it that works in a Class. without worrying about scope. Mine relies heavily upon scope. Anyone have any example? Thanks, V -- Original Message -- From: Dan Rogers [EMAIL PROTECTED] Reply-To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Date: Tue, 26 Sep 2006 20:55:32 -0700 Vic, if you've ever used the XML or NetStream classes... it mimics those types of event updates. For example... var xmlData = new XML(); xmlData.onLoad = function () { // gets invoked by the XML instance } So if you delegate the onLoad method, you get something like this: xmlData.onLoad = Delegate.create(this, xmlDataLoad); ... which is essentially what I am trying to do with my own classes. Another reason I like delegating events this way, is that the compiler will catch typos in the names of the event functions, so I am not searching around trying to figure out why a certain event is not firing. -Danro On Sep 26, 2006, at 7:06 PM, vic wrote: Hey Dan, I like the way you do it, its pretty simple. But here is, what probably will be an incredibly stupid question: How do I capture the event? Thanks, V 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 ___ 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 ___ 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