Re: [Flashcoders] Events for custom classes?
On 4/3/07, Helmut Granda [EMAIL PROTECTED] wrote: Jason, Were you able to figure this out exactly the way you wanted it? -h On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: Ah - nevermind - figured out I had removed the scope to my webservice and forgot to put it back in. Delegate works fine for me now, sorry about the noise, and thanks so much everyone for the help!! Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Helmut Granda Sent: Tuesday, April 03, 2007 12:35 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Events for custom classes? On 4/3/07, Helmut Granda [EMAIL PROTECTED] wrote: Jason, Were you able to figure this out exactly the way you wanted it? -h On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: Ah - nevermind - figured out I had removed the scope to my webservice and forgot to put it back in. Delegate works fine for me now, sorry about the noise, and thanks so much everyone for the help!! Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
You'll need a reference of the dispatching class in your listener class to receive events: // broadcasting class import mx.events.EventDispatcher; class EventClass { // EventDispatcher methods public var addEventListener:Function; public var removeEventListener:Function; private var dispatchEvent:Function; public function EventClass() { } public function onInit():Void { trace('onInit fired!'); dispatchEvent({type: onInit, target: this}); } } // listener class import mx.utils.Delegate; class ListenerClass { public function ListenerClass(eventClass:MyEventClass) { eventClass.addEventListener(onInit, Delegate.create(this, onInitHandler)); } private function onInitHandler(event:Object):Void { trace('onInitHandler invoked'); } } // implementation var eventClass:EventClass = new EventClass(); var listenerClass:ListenerClass = new ListenerClass(eventClass); eventClass.onInit(); -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Tuesday, April 03, 2007 9:47 AM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Events for custom classes? Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Helmut Granda Sent: Tuesday, April 03, 2007 12:35 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Events for custom classes? On 4/3/07, Helmut Granda [EMAIL PROTECTED] wrote: Jason, Were you able to figure this out exactly the way you wanted it? -h On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: Ah - nevermind - figured out I had removed the scope to my webservice and forgot to put it back in. Delegate works fine for me now, sorry about the noise, and thanks so much everyone for the help!! Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
Is this what you're looking for? http://www.adobe.com/devnet/flash/articles/creating_events.html john On Apr 3, 2007, at 12:46 PM, Merrill, Jason wrote: Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team ___ 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] Events for custom classes?
Excellent, thanks David Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Ngo Sent: Tuesday, April 03, 2007 1:46 PM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Events for custom classes? You'll need a reference of the dispatching class in your listener class to receive events: // broadcasting class import mx.events.EventDispatcher; class EventClass { // EventDispatcher methods public var addEventListener:Function; public var removeEventListener:Function; private var dispatchEvent:Function; public function EventClass() { } public function onInit():Void { trace('onInit fired!'); dispatchEvent({type: onInit, target: this}); } } // listener class import mx.utils.Delegate; class ListenerClass { public function ListenerClass(eventClass:MyEventClass) { eventClass.addEventListener(onInit, Delegate.create(this, onInitHandler)); } private function onInitHandler(event:Object):Void { trace('onInitHandler invoked'); } } // implementation var eventClass:EventClass = new EventClass(); var listenerClass:ListenerClass = new ListenerClass(eventClass); eventClass.onInit(); -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Tuesday, April 03, 2007 9:47 AM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Events for custom classes? Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Helmut Granda Sent: Tuesday, April 03, 2007 12:35 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Events for custom classes? On 4/3/07, Helmut Granda [EMAIL PROTECTED] wrote: Jason, Were you able to figure this out exactly the way you wanted it? -h On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: Ah - nevermind - figured out I had removed the scope to my webservice and forgot to put it back in. Delegate works fine for me now, sorry about the noise, and thanks so much everyone for the help!! Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
Here's a stripped down version (i just left in the methods that dispatch en event) of my Form base class that uses EventDispatcher. This class is usually extended by other classes (in an ARP-type framework). import mx.events.EventDispatcher; class com.muzakdeezign.core.Form extends MovieClip { static var symbolName:String = Form; static var symbolOwner = Object(com.muzakdeezign.core.Form); var className:String = Form; // allow class to broadcast events private static var dispatcherInit = EventDispatcher.initialize(Object(com.muzakdeezign.core.Form.prototype)); // mix-in from EventDispatcher var addEventListener:Function; var removeEventListener:Function; var dispatchEvent:Function; var dispatchQueue:Function; // // CONSTRUCTOR // function Form() { // trace(Form ::: CONSTRUCTOR); } // // PRIVATE METHODS // private function size():Void { // should be overridden by sub class this.dispatchEvent({type:size}); } // // PUBLIC METHODS // public function move(x:Number, y:Number, noEvent:Boolean):Void { // trace(Form ::: move); // code removed... if (noEvent != true) { dispatchEvent({type:move, oldX:oldX, oldY:oldY}); } } public function show():Void { // trace(Form ::: show) this._visible = true; this.dispatchEvent({type:reveal}); } public function hide():Void { // trace(FORM ::: hide) this._visible = false; this.dispatchEvent({type:hide}); } } So assume you then have 2 classes, Application and Login both extending the Form class and Login is a movieclip inside Application (Login is a child of Application). The Application could then listen to events dispatched by the Login. import com.muzakdeezign.core.Form; import mx.utils.Delegate; class Application extends Form { private var login_frm:Login; private function onLoad() { login_frm.addEventListener(show, Delegate.create(this, this.loginShowHandler)); login_frm.addEventListener(hide, Delegate.create(this, this.loginHideHandler)); } private function loginShowHandler(evt:Object):Void { // login is visible } private function loginHideHandler(evt:Object):Void { // login is hidden } } Note that the Login doesn't listen for events dispatched by the Application because: - children don't listen to parents ;-) If Application had 2 child forms (Login, SomeView), those children wouldn't communicate with eachother directly, but through the parent (Application) by dispatching events. For instance when a user logs in, the Login form could dispatch a loggedIn event to inform the Application that a login was successful. The Application would then respond to that by hiding the Login form and showing the SomeView form. import com.muzakdeezign.core.Form; import mx.utils.Delegate; class Application extends Form { private var login_frm:Login; private var view_frm:SomeView; private function onLoad() { view_frm.hide(); login_frm.addEventListener(loggedIn, Delegate.create(this, this.loginLoggedInHandler)); } private function loginLoggedInHandler(evt:Object):Void { // login was successful // hide login and show other form login_frm.hide(); view_frm.show(); } } Does this help? regards, Muzak - Original Message - From: Merrill, Jason [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Tuesday, April 03, 2007 6:46 PM Subject: RE: [Flashcoders] Events for custom classes? Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team ___ 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] Events for custom classes?
Ick. I totally forgot to initialize EventDispatcher. Constructor for EventClass should be: public function EventClass() { EventDispatcher.initialize(this); } -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of David Ngo Sent: Tuesday, April 03, 2007 10:46 AM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Events for custom classes? You'll need a reference of the dispatching class in your listener class to receive events: // broadcasting class import mx.events.EventDispatcher; class EventClass { // EventDispatcher methods public var addEventListener:Function; public var removeEventListener:Function; private var dispatchEvent:Function; public function EventClass() { } public function onInit():Void { trace('onInit fired!'); dispatchEvent({type: onInit, target: this}); } } // listener class import mx.utils.Delegate; class ListenerClass { public function ListenerClass(eventClass:MyEventClass) { eventClass.addEventListener(onInit, Delegate.create(this, onInitHandler)); } private function onInitHandler(event:Object):Void { trace('onInitHandler invoked'); } } // implementation var eventClass:EventClass = new EventClass(); var listenerClass:ListenerClass = new ListenerClass(eventClass); eventClass.onInit(); -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Tuesday, April 03, 2007 9:47 AM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Events for custom classes? Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Helmut Granda Sent: Tuesday, April 03, 2007 12:35 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Events for custom classes? On 4/3/07, Helmut Granda [EMAIL PROTECTED] wrote: Jason, Were you able to figure this out exactly the way you wanted it? -h On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: Ah - nevermind - figured out I had removed the scope to my webservice and forgot to put it back in. Delegate works fine for me now, sorry about the noise, and thanks so much everyone for the help!! Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
great - thanks. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of john robinson Sent: Tuesday, April 03, 2007 1:48 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Events for custom classes? Is this what you're looking for? http://www.adobe.com/devnet/flash/articles/creating_events.html john On Apr 3, 2007, at 12:46 PM, Merrill, Jason wrote: Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team ___ 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] Events for custom classes?
: import vegas.events.BasicEvent ; import vegas.events.Delegate ; import vegas.events.Event ; import vegas.events.EventDispatcher ; import vegas.events.FrontController ; var action:Function = function (ev:Event) { trace( + this + :: + ev.getType() + - + ev.getTarget()) ; } var listener = {} ; listener.handleEvent = function(ev:Event):Void { trace( + this + :: + ev.getType() + - + ev.getTarget()) ; } listener.toString = function () { return [MY_LISTENER] ; } var controller:FrontController = new FrontController( ) ; controller.insert(MY_EVENT1, new Delegate(this, action)) ; controller.insert(MY_EVENT2, listener) ; // Test EventDispatcher.getInstance().dispatchEvent( new BasicEvent(MY_EVENT1, this) ) ; trace(---) ; EventDispatcher.getInstance().dispatchEvent( new BasicEvent(MY_EVENT2, this) ) ; For me it's the best solution to use an event model AS2 like AS3 ! EKA+ :) 2007/4/3, David Ngo [EMAIL PROTECTED]: You'll need a reference of the dispatching class in your listener class to receive events: // broadcasting class import mx.events.EventDispatcher; class EventClass { // EventDispatcher methods public var addEventListener:Function; public var removeEventListener:Function; private var dispatchEvent:Function; public function EventClass() { } public function onInit():Void { trace('onInit fired!'); dispatchEvent({type: onInit, target: this}); } } // listener class import mx.utils.Delegate; class ListenerClass { public function ListenerClass(eventClass:MyEventClass) { eventClass.addEventListener(onInit, Delegate.create (this, onInitHandler)); } private function onInitHandler(event:Object):Void { trace('onInitHandler invoked'); } } // implementation var eventClass:EventClass = new EventClass(); var listenerClass:ListenerClass = new ListenerClass(eventClass); eventClass.onInit(); -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Tuesday, April 03, 2007 9:47 AM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Events for custom classes? Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Helmut Granda Sent: Tuesday, April 03, 2007 12:35 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Events for custom classes? On 4/3/07, Helmut Granda [EMAIL PROTECTED] wrote: Jason, Were you able to figure this out exactly the way you wanted it? -h On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: Ah - nevermind - figured out I had removed the scope to my webservice and forgot to put it back in. Delegate works fine for me now, sorry about the noise, and thanks so much everyone for the help!! Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
Yes - thanks Muzak - I can't speak for Helmut, but I've got enough to go on now. Thanks, Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Muzak Sent: Tuesday, April 03, 2007 2:09 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Events for custom classes? Here's a stripped down version (i just left in the methods that dispatch en event) of my Form base class that uses EventDispatcher. This class is usually extended by other classes (in an ARP-type framework). import mx.events.EventDispatcher; class com.muzakdeezign.core.Form extends MovieClip { static var symbolName:String = Form; static var symbolOwner = Object(com.muzakdeezign.core.Form); var className:String = Form; // allow class to broadcast events private static var dispatcherInit = EventDispatcher.initialize(Object(com.muzakdeezign.core.Form.p rototype)); // mix-in from EventDispatcher var addEventListener:Function; var removeEventListener:Function; var dispatchEvent:Function; var dispatchQueue:Function; // // // // CONSTRUCTOR // // // function Form() { // trace(Form ::: CONSTRUCTOR); } // // // // PRIVATE METHODS // // // private function size():Void { // should be overridden by sub class this.dispatchEvent({type:size}); } // // // // PUBLIC METHODS // // // public function move(x:Number, y:Number, noEvent:Boolean):Void { // trace(Form ::: move); // code removed... if (noEvent != true) { dispatchEvent({type:move, oldX:oldX, oldY:oldY}); } } public function show():Void { // trace(Form ::: show) this._visible = true; this.dispatchEvent({type:reveal}); } public function hide():Void { // trace(FORM ::: hide) this._visible = false; this.dispatchEvent({type:hide}); } } So assume you then have 2 classes, Application and Login both extending the Form class and Login is a movieclip inside Application (Login is a child of Application). The Application could then listen to events dispatched by the Login. import com.muzakdeezign.core.Form; import mx.utils.Delegate; class Application extends Form { private var login_frm:Login; private function onLoad() { login_frm.addEventListener(show, Delegate.create(this, this.loginShowHandler)); login_frm.addEventListener(hide, Delegate.create(this, this.loginHideHandler)); } private function loginShowHandler(evt:Object):Void { // login is visible } private function loginHideHandler(evt:Object):Void { // login is hidden } } Note that the Login doesn't listen for events dispatched by the Application because: - children don't listen to parents ;-) If Application had 2 child forms (Login, SomeView), those children wouldn't communicate with eachother directly, but through the parent (Application) by dispatching events. For instance when a user logs in, the Login form could dispatch a loggedIn event to inform the Application that a login was successful. The Application would then respond to that by hiding the Login form and showing the SomeView form. import com.muzakdeezign.core.Form; import mx.utils.Delegate; class Application extends Form { private var login_frm:Login; private var view_frm:SomeView; private function onLoad() { view_frm.hide(); login_frm.addEventListener(loggedIn, Delegate.create(this, this.loginLoggedInHandler)); } private function loginLoggedInHandler(evt:Object):Void { // login was successful // hide login and show other form login_frm.hide(); view_frm.show(); } } Does this help? regards, Muzak - Original Message - From: Merrill, Jason [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Tuesday, April 03, 2007 6:46 PM Subject: RE: [Flashcoders] Events for custom classes? Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team ___ Flashcoders@chattyfig.figleaf.com
Re: [Flashcoders] Events for custom classes?
Thanks for this sample David, Just a small correction: public function ListenerClass(eventClass:MyEventClass) should be public function ListenerClass(eventClass:EventClass); Correct? -h On 4/3/07, David Ngo [EMAIL PROTECTED] wrote: You'll need a reference of the dispatching class in your listener class to receive events: // broadcasting class import mx.events.EventDispatcher; class EventClass { // EventDispatcher methods public var addEventListener:Function; public var removeEventListener:Function; private var dispatchEvent:Function; public function EventClass() { } public function onInit():Void { trace('onInit fired!'); dispatchEvent({type: onInit, target: this}); } } // listener class import mx.utils.Delegate; class ListenerClass { public function ListenerClass(eventClass:MyEventClass) { eventClass.addEventListener(onInit, Delegate.create (this, onInitHandler)); } private function onInitHandler(event:Object):Void { trace('onInitHandler invoked'); } } // implementation var eventClass:EventClass = new EventClass(); var listenerClass:ListenerClass = new ListenerClass(eventClass); eventClass.onInit(); -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Tuesday, April 03, 2007 9:47 AM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Events for custom classes? Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Helmut Granda Sent: Tuesday, April 03, 2007 12:35 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Events for custom classes? On 4/3/07, Helmut Granda [EMAIL PROTECTED] wrote: Jason, Were you able to figure this out exactly the way you wanted it? -h On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: Ah - nevermind - figured out I had removed the scope to my webservice and forgot to put it back in. Delegate works fine for me now, sorry about the noise, and thanks so much everyone for the help!! Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
Yeah, same here, trying to digest everything now that I have my mouth full :). Thanks again everyone! On 4/3/07, Merrill, Jason [EMAIL PROTECTED] wrote: Yes - thanks Muzak - I can't speak for Helmut, but I've got enough to go on now. Thanks, Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Muzak Sent: Tuesday, April 03, 2007 2:09 PM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Events for custom classes? Here's a stripped down version (i just left in the methods that dispatch en event) of my Form base class that uses EventDispatcher. This class is usually extended by other classes (in an ARP-type framework). import mx.events.EventDispatcher; class com.muzakdeezign.core.Form extends MovieClip { static var symbolName:String = Form; static var symbolOwner = Object(com.muzakdeezign.core.Form); var className:String = Form; // allow class to broadcast events private static var dispatcherInit = EventDispatcher.initialize(Object(com.muzakdeezign.core.Form.p rototype)); // mix-in from EventDispatcher var addEventListener:Function; var removeEventListener:Function; var dispatchEvent:Function; var dispatchQueue:Function; // // // // CONSTRUCTOR // // // function Form() { // trace(Form ::: CONSTRUCTOR); } // // // // PRIVATE METHODS // // // private function size():Void { // should be overridden by sub class this.dispatchEvent({type:size}); } // // // // PUBLIC METHODS // // // public function move(x:Number, y:Number, noEvent:Boolean):Void { // trace(Form ::: move); // code removed... if (noEvent != true) { dispatchEvent({type:move, oldX:oldX, oldY:oldY}); } } public function show():Void { // trace(Form ::: show) this._visible = true; this.dispatchEvent({type:reveal}); } public function hide():Void { // trace(FORM ::: hide) this._visible = false; this.dispatchEvent({type:hide}); } } So assume you then have 2 classes, Application and Login both extending the Form class and Login is a movieclip inside Application (Login is a child of Application). The Application could then listen to events dispatched by the Login. import com.muzakdeezign.core.Form; import mx.utils.Delegate; class Application extends Form { private var login_frm:Login; private function onLoad() { login_frm.addEventListener(show, Delegate.create(this, this.loginShowHandler)); login_frm.addEventListener(hide, Delegate.create(this, this.loginHideHandler)); } private function loginShowHandler(evt:Object):Void { // login is visible } private function loginHideHandler(evt:Object):Void { // login is hidden } } Note that the Login doesn't listen for events dispatched by the Application because: - children don't listen to parents ;-) If Application had 2 child forms (Login, SomeView), those children wouldn't communicate with eachother directly, but through the parent (Application) by dispatching events. For instance when a user logs in, the Login form could dispatch a loggedIn event to inform the Application that a login was successful. The Application would then respond to that by hiding the Login form and showing the SomeView form. import com.muzakdeezign.core.Form; import mx.utils.Delegate; class Application extends Form { private var login_frm:Login; private var view_frm:SomeView; private function onLoad() { view_frm.hide(); login_frm.addEventListener(loggedIn, Delegate.create(this, this.loginLoggedInHandler)); } private function loginLoggedInHandler(evt:Object):Void { // login was successful // hide login and show other form login_frm.hide(); view_frm.show(); } } Does this help? regards, Muzak - Original Message - From: Merrill, Jason [EMAIL PROTECTED] To: flashcoders@chattyfig.figleaf.com Sent: Tuesday, April 03, 2007 6:46 PM Subject: RE: [Flashcoders] Events for custom classes? Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning
RE: [Flashcoders] Events for custom classes?
Yes, that would be correct. I initially named them MyEvent/ListenerClass but changed it halfway through writing the email. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Helmut Granda Sent: Tuesday, April 03, 2007 11:54 AM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Events for custom classes? Thanks for this sample David, Just a small correction: public function ListenerClass(eventClass:MyEventClass) should be public function ListenerClass(eventClass:EventClass); Correct? -h On 4/3/07, David Ngo [EMAIL PROTECTED] wrote: You'll need a reference of the dispatching class in your listener class to receive events: // broadcasting class import mx.events.EventDispatcher; class EventClass { // EventDispatcher methods public var addEventListener:Function; public var removeEventListener:Function; private var dispatchEvent:Function; public function EventClass() { } public function onInit():Void { trace('onInit fired!'); dispatchEvent({type: onInit, target: this}); } } // listener class import mx.utils.Delegate; class ListenerClass { public function ListenerClass(eventClass:MyEventClass) { eventClass.addEventListener(onInit, Delegate.create (this, onInitHandler)); } private function onInitHandler(event:Object):Void { trace('onInitHandler invoked'); } } // implementation var eventClass:EventClass = new EventClass(); var listenerClass:ListenerClass = new ListenerClass(eventClass); eventClass.onInit(); -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Tuesday, April 03, 2007 9:47 AM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] Events for custom classes? Actually, I had been meaning to post again because I had lost my code for getting EventDispatcher working between two classes. Someone posted a response here and I lost it, as well as my code that was working. if anyone can post again on how to get one class to dispatch a CUSTOM event and get another CUSTOM class to listen to that event, please post! Helmut and I would like to see an example. The help docs on EventDispatcher are really awful, and I haven't seen a lot of stuff online. Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Helmut Granda Sent: Tuesday, April 03, 2007 12:35 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Events for custom classes? On 4/3/07, Helmut Granda [EMAIL PROTECTED] wrote: Jason, Were you able to figure this out exactly the way you wanted it? -h On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: Ah - nevermind - figured out I had removed the scope to my webservice and forgot to put it back in. Delegate works fine for me now, sorry about the noise, and thanks so much everyone for the help!! Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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
Re: [Flashcoders] Events for custom classes?
Use EventDispatcher: How: http://chattyfig.figleaf.com/pipermail/flashcoders/2006-February/160302.html Why: http://chattyfig.figleaf.com/pipermail/flashcoders/2004-June/114320.html found with Muzak's archive search tool: http://muzakdeezign.com/flashcoders/ Helen Merrill, Jason wrote: Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? ___ 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] Events for custom classes?
I'm not sure if you're asking for this level of explanation or not Jason, but this might help: I use a BaseClass.as to extend so that I can dispatch events via GDispatcher: import com.blitzagency.xray.logger.XrayLog; import com.gskinner.events.GDispatcher; /** * @author John Grden */ class com.tomsnyder.util.BaseClass { // Public Properties: public var addEventListener:Function; public var removeEventListener:Function; public var removeAllEventListeners:Function; // Private Properties: private var dispatchEvent:Function; private var log:XrayLog; function BaseClass() { GDispatcher.initialize(this); log = new XrayLog(); } } So, with this, I just create a new class that extends BaseClass, and bingo, I have eventDispatching capabilities: import com.tomsnyder.util.BaseClass; /** * @author John Grden */ class BaseMain extends BaseClass { public static var SOMETHING_COMPLETE:String = somethingComplete; function BaseMain() { super(); } } Now, I can just as easily add my listener from another class that has access to BaseMain: BaseMain.addEventListener(BaseMain.SOMETHING_COMPLETE, Delegate.create(this, somethingCompleteHandler)); private function somethingCompleteHandler(e:Object):Void { trace(log.debug(somethingCompleteHandler called, e)); } For scope, just use mx.utils.Delegate or Steve Websters delegate Does that help or am I missing your question? John On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: OK, I'm pretty good at Actionscript 2.0, but something I never really understood and now need to. Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? EventBroadcaster in the help docs seems to only show how to use it with Adobe classes and components. Docs on listener are the same. I know how to set up listeners for other events, like keypresses and mouse rollovers. Easy enough. But my problem is this (see comments in code below): class com.boa.projects.iqrcgenerator.components.AdminData{ private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); getUserListResult.onResult = function(oUser){ //this works fine, //I can capture this event result here, //but how do I notify another class? //also what about scope here? //how to set userData as oUser result? //can I fire an event in my AdminData //class from here? } } public function getUserData():Object{ //can't let user get this data //until Webserive event is done. return userData; } } Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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 -- [ JPG ] ___ 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] Events for custom classes?
Helen, Great, thank you. However, I'm a little confused on how I apply that to my code I posted. All the MM docs on Event Dispatcher show using it with Adove classes or components. And how about the scope with my Webservice event? That scope is outside of my custom class, so how do I fire the event in my custom class? I can add a property to the listener object which is the AdminData class instance, but that seems kludgy. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Helen Triolo Sent: Friday, February 16, 2007 10:15 AM To: Flashcoders mailing list Subject: Re: [Flashcoders] Events for custom classes? Use EventDispatcher: How: http://chattyfig.figleaf.com/pipermail/flashcoders/2006-Februa ry/160302.html Why: http://chattyfig.figleaf.com/pipermail/flashcoders/2004-June/1 14320.html found with Muzak's archive search tool: http://muzakdeezign.com/flashcoders/ Helen Merrill, Jason wrote: Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? ___ 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] Events for custom classes?
Oh and the last part, dispatching the event: from BaseMain.as: dispatchEvent( { type:SOMETHING_COMPLETE } ); hth, On 2/16/07, John Grden [EMAIL PROTECTED] wrote: I'm not sure if you're asking for this level of explanation or not Jason, but this might help: I use a BaseClass.as to extend so that I can dispatch events via GDispatcher: import com.blitzagency.xray.logger.XrayLog; import com.gskinner.events.GDispatcher; /** * @author John Grden */ class com.tomsnyder.util.BaseClass { // Public Properties: public var addEventListener:Function; public var removeEventListener:Function; public var removeAllEventListeners:Function; // Private Properties: private var dispatchEvent:Function; private var log:XrayLog; function BaseClass() { GDispatcher.initialize(this); log = new XrayLog(); } } So, with this, I just create a new class that extends BaseClass, and bingo, I have eventDispatching capabilities: import com.tomsnyder.util.BaseClass; /** * @author John Grden */ class BaseMain extends BaseClass { public static var SOMETHING_COMPLETE:String = somethingComplete; function BaseMain() { super(); } } Now, I can just as easily add my listener from another class that has access to BaseMain: BaseMain.addEventListener(BaseMain.SOMETHING_COMPLETE, Delegate.create(this, somethingCompleteHandler)); private function somethingCompleteHandler(e:Object):Void { trace(log.debug(somethingCompleteHandler called, e)); } For scope, just use mx.utils.Delegate or Steve Websters delegate Does that help or am I missing your question? John On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: OK, I'm pretty good at Actionscript 2.0, but something I never really understood and now need to. Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? EventBroadcaster in the help docs seems to only show how to use it with Adobe classes and components. Docs on listener are the same. I know how to set up listeners for other events, like keypresses and mouse rollovers. Easy enough. But my problem is this (see comments in code below): class com.boa.projects.iqrcgenerator.components.AdminData{ private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList (lobDbId); getUserListResult.onResult = function(oUser){ //this works fine, //I can capture this event result here, //but how do I notify another class? //also what about scope here? //how to set userData as oUser result? //can I fire an event in my AdminData //class from here? } } public function getUserData():Object{ //can't let user get this data //until Webserive event is done. return userData; } } Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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 -- [ JPG ] -- [ JPG ] ___ 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] Events for custom classes?
Cool John, I'll check into this. Thanks Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Grden Sent: Friday, February 16, 2007 10:17 AM To: Flashcoders mailing list Subject: Re: [Flashcoders] Events for custom classes? I'm not sure if you're asking for this level of explanation or not Jason, but this might help: I use a BaseClass.as to extend so that I can dispatch events via GDispatcher: import com.blitzagency.xray.logger.XrayLog; import com.gskinner.events.GDispatcher; /** * @author John Grden */ class com.tomsnyder.util.BaseClass { // Public Properties: public var addEventListener:Function; public var removeEventListener:Function; public var removeAllEventListeners:Function; // Private Properties: private var dispatchEvent:Function; private var log:XrayLog; function BaseClass() { GDispatcher.initialize(this); log = new XrayLog(); } } So, with this, I just create a new class that extends BaseClass, and bingo, I have eventDispatching capabilities: import com.tomsnyder.util.BaseClass; /** * @author John Grden */ class BaseMain extends BaseClass { public static var SOMETHING_COMPLETE:String = somethingComplete; function BaseMain() { super(); } } Now, I can just as easily add my listener from another class that has access to BaseMain: BaseMain.addEventListener(BaseMain.SOMETHING_COMPLETE, Delegate.create(this, somethingCompleteHandler)); private function somethingCompleteHandler(e:Object):Void { trace(log.debug(somethingCompleteHandler called, e)); } For scope, just use mx.utils.Delegate or Steve Websters delegate Does that help or am I missing your question? John On 2/16/07, Merrill, Jason [EMAIL PROTECTED] wrote: OK, I'm pretty good at Actionscript 2.0, but something I never really understood and now need to. Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? EventBroadcaster in the help docs seems to only show how to use it with Adobe classes and components. Docs on listener are the same. I know how to set up listeners for other events, like keypresses and mouse rollovers. Easy enough. But my problem is this (see comments in code below): class com.boa.projects.iqrcgenerator.components.AdminData{ private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); getUserListResult.onResult = function(oUser){ //this works fine, //I can capture this event result here, //but how do I notify another class? //also what about scope here? //how to set userData as oUser result? //can I fire an event in my AdminData //class from here? } } public function getUserData():Object{ //can't let user get this data //until Webserive event is done. return userData; } } Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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 -- [ JPG ] ___ 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] Events for custom classes?
Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions private var userData:Object; // I'm sure you have a different constructor, but you need // to add that line to it if you want to use the eventdispatcher public function AdminData(){ mx.events.EventDispatcher.initialize(this); // add this to constructor } public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); var r = this; // To get this in onResult getUserListResult.onResult = function(oUser){ r.dispatchEvent({type:eventOnResult, user:oUser}); // Dispatch the event } } // I may just take this function out all together since the event can // autommatically send them the data. public function getUserData():Object{ return userData; } } Then in your other class you can do something like: //myAdminData is an instance of the class above var r = this; r.eventOnResult= function(evtObj:Object){ trace(user: + evtObj.user); // Should return the oUser object } // addEventListener takes the event name, and who you want to listen myAdminData.addEventListener(eventOnResult, r); Does that help? I obviously can't test the code, but I think everything is right... I have trouble with scope, which is why I use a lot of 'r' values instead of 'this'... Just easier for me... Probably not a good coding standard :) -Dan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Friday, February 16, 2007 9:03 AM To: Flashcoders mailing list Subject: [Flashcoders] Events for custom classes? OK, I'm pretty good at Actionscript 2.0, but something I never really understood and now need to. Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? EventBroadcaster in the help docs seems to only show how to use it with Adobe classes and components. Docs on listener are the same. I know how to set up listeners for other events, like keypresses and mouse rollovers. Easy enough. But my problem is this (see comments in code below): class com.boa.projects.iqrcgenerator.components.AdminData{ private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); getUserListResult.onResult = function(oUser){ //this works fine, //I can capture this event result here, //but how do I notify another class? //also what about scope here? //how to set userData as oUser result? //can I fire an event in my AdminData //class from here? } } public function getUserData():Object{ //can't let user get this data //until Webserive event is done. return userData; } } Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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 This e-mail and its attachments are intended only for the use of the addressee(s) and may contain privileged, confidential or proprietary information. If you are not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution, displaying, copying, or use of this information is strictly prohibited. If you have received this communication in error, please inform the sender immediately and delete and destroy any record of this message. Thank you. ___ 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
Re: [Flashcoders] Events for custom classes?
If you use dispatchEvent from any class, any other class that's listening for it can respond. No scope issues that I can see. I have a simple example of two classes talking to each other using EventDispatcher at http://flash-creations.com/notes/sample_emailer.php if you want it -- click the free download on the right. Helen Merrill, Jason wrote: Helen, Great, thank you. However, I'm a little confused on how I apply that to my code I posted. All the MM docs on Event Dispatcher show using it with Adove classes or components. And how about the scope with my Webservice event? That scope is outside of my custom class, so how do I fire the event in my custom class? I can add a property to the listener object which is the AdminData class instance, but that seems kludgy. Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
Awesome Daniel, will try that out. Thank you!!! Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February 16, 2007 10:36 AM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions private var userData:Object; // I'm sure you have a different constructor, but you need // to add that line to it if you want to use the eventdispatcher public function AdminData(){ mx.events.EventDispatcher.initialize(this); // add this to constructor } public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); var r = this; // To get this in onResult getUserListResult.onResult = function(oUser){ r.dispatchEvent({type:eventOnResult, user:oUser}); // Dispatch the event } } // I may just take this function out all together since the event can // autommatically send them the data. public function getUserData():Object{ return userData; } } Then in your other class you can do something like: //myAdminData is an instance of the class above var r = this; r.eventOnResult= function(evtObj:Object){ trace(user: + evtObj.user); // Should return the oUser object } // addEventListener takes the event name, and who you want to listen myAdminData.addEventListener(eventOnResult, r); Does that help? I obviously can't test the code, but I think everything is right... I have trouble with scope, which is why I use a lot of 'r' values instead of 'this'... Just easier for me... Probably not a good coding standard :) -Dan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Friday, February 16, 2007 9:03 AM To: Flashcoders mailing list Subject: [Flashcoders] Events for custom classes? OK, I'm pretty good at Actionscript 2.0, but something I never really understood and now need to. Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? EventBroadcaster in the help docs seems to only show how to use it with Adobe classes and components. Docs on listener are the same. I know how to set up listeners for other events, like keypresses and mouse rollovers. Easy enough. But my problem is this (see comments in code below): class com.boa.projects.iqrcgenerator.components.AdminData{ private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); getUserListResult.onResult = function(oUser){ //this works fine, //I can capture this event result here, //but how do I notify another class? //also what about scope here? //how to set userData as oUser result? //can I fire an event in my AdminData //class from here? } } public function getUserData():Object{ //can't let user get this data //until Webserive event is done. return userData; } } Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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 This e-mail and its attachments are intended only for the use of the addressee(s) and may contain privileged, confidential or proprietary information. If you are not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution, displaying, copying, or use of this information is strictly prohibited. If you have received this communication in error, please inform the sender immediately and delete and destroy any record of this message. Thank you
RE: [Flashcoders] Events for custom classes?
Also if you want to create your own onResult Event (it's not a real event) you can do this without EventDispatcher or listeners : class com.boa.projects.iqrcgenerator.components.AdminData{ public var onResult:Function; private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult =generatorWebService.GetUserList(lobDbId); getUserListResult.onResult = Delegate.create(this, resultHandler); } private function resultHandler(oUser:object) { // handle the data however you want .. // now trigger the onResult method this.onResult(oUser); } //... the rest of your class below } Now in another class where you import AdminData with say an instance called admData : var admData:AdminData = new AdminData(); admData.onResult = function(oUser) { // your code handling here } As for a method with EventDispatcher, you'll find pretty much what you need with what the others gave you ! :) HTH ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 10:03 To: Flashcoders mailing list Subject: [Flashcoders] Events for custom classes? OK, I'm pretty good at Actionscript 2.0, but something I never really understood and now need to. Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? EventBroadcaster in the help docs seems to only show how to use it with Adobe classes and components. Docs on listener are the same. I know how to set up listeners for other events, like keypresses and mouse rollovers. Easy enough. But my problem is this (see comments in code below): class com.boa.projects.iqrcgenerator.components.AdminData{ private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); getUserListResult.onResult = function(oUser){ //this works fine, //I can capture this event result here, //but how do I notify another class? //also what about scope here? //how to set userData as oUser result? //can I fire an event in my AdminData //class from here? } } public function getUserData():Object{ //can't let user get this data //until Webserive event is done. return userData; } } Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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 -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.412 / Virus Database: 268.18.0/689 - Release Date: 2007-02-15 -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.412 / Virus Database: 268.18.0/689 - Release Date: 2007-02-15 ___ 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] Events for custom classes?
Very cool Alain, thank you. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 11:00 AM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Also if you want to create your own onResult Event (it's not a real event) you can do this without EventDispatcher or listeners : class com.boa.projects.iqrcgenerator.components.AdminData{ public var onResult:Function; private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult =generatorWebService.GetUserList(lobDbId); getUserListResult.onResult = Delegate.create(this, resultHandler); } private function resultHandler(oUser:object) { // handle the data however you want .. // now trigger the onResult method this.onResult(oUser); } //... the rest of your class below } Now in another class where you import AdminData with say an instance called admData : var admData:AdminData = new AdminData(); admData.onResult = function(oUser) { // your code handling here } As for a method with EventDispatcher, you'll find pretty much what you need with what the others gave you ! :) HTH ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 10:03 To: Flashcoders mailing list Subject: [Flashcoders] Events for custom classes? OK, I'm pretty good at Actionscript 2.0, but something I never really understood and now need to. Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? EventBroadcaster in the help docs seems to only show how to use it with Adobe classes and components. Docs on listener are the same. I know how to set up listeners for other events, like keypresses and mouse rollovers. Easy enough. But my problem is this (see comments in code below): class com.boa.projects.iqrcgenerator.components.AdminData{ private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); getUserListResult.onResult = function(oUser){ //this works fine, //I can capture this event result here, //but how do I notify another class? //also what about scope here? //how to set userData as oUser result? //can I fire an event in my AdminData //class from here? } } public function getUserData():Object{ //can't let user get this data //until Webserive event is done. return userData; } } Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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 -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.412 / Virus Database: 268.18.0/689 - Release Date: 2007-02-15 -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.412 / Virus Database: 268.18.0/689 - Release Date: 2007-02-15 ___ 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] Events for custom classes?
Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B - I'm confused about that. Thanks for any help. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February 16, 2007 10:36 AM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions private var userData:Object; // I'm sure you have a different constructor, but you need // to add that line to it if you want to use the eventdispatcher public function AdminData(){ mx.events.EventDispatcher.initialize(this); // add this to constructor } public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); var r = this; // To get this in onResult getUserListResult.onResult = function(oUser){ r.dispatchEvent({type:eventOnResult, user:oUser}); // Dispatch the event } } // I may just take this function out all together since the event can // autommatically send them the data. public function getUserData():Object{ return userData; } } Then in your other class you can do something like: //myAdminData is an instance of the class above var r = this; r.eventOnResult= function(evtObj:Object){ trace(user: + evtObj.user); // Should return the oUser object } // addEventListener takes the event name, and who you want to listen myAdminData.addEventListener(eventOnResult, r); Does that help? I obviously can't test the code, but I think everything is right... I have trouble with scope, which is why I use a lot of 'r' values instead of 'this'... Just easier for me... Probably not a good coding standard :) -Dan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Friday, February 16, 2007 9:03 AM To: Flashcoders mailing list Subject: [Flashcoders] Events for custom classes? OK, I'm pretty good at Actionscript 2.0, but something I never really understood and now need to. Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? EventBroadcaster in the help docs seems to only show how to use it with Adobe classes and components. Docs on listener are the same. I know how to set up listeners for other events, like keypresses and mouse rollovers. Easy enough. But my problem is this (see comments in code below): class com.boa.projects.iqrcgenerator.components.AdminData{ private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); getUserListResult.onResult = function(oUser){ //this works fine, //I can capture this event result here, //but how do I notify another class? //also what about scope here? //how to set userData as oUser result? //can I fire an event in my AdminData //class from
Re: [Flashcoders] Events for custom classes?
do you have a reference to the class that is broadcasting the event in the class that's listening for the event? meaning, when you write your addEventListener in your Receiving class, you should have: referenceToBroadcastingClass.addEventListener(myEvent,myHandler); - Original Message - From: Merrill, Jason [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Friday, February 16, 2007 2:35 PM Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B - I'm confused about that. Thanks for any help. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February 16, 2007 10:36 AM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions private var userData:Object; // I'm sure you have a different constructor, but you need // to add that line to it if you want to use the eventdispatcher public function AdminData(){ mx.events.EventDispatcher.initialize(this); // add this to constructor } public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); var r = this; // To get this in onResult getUserListResult.onResult = function(oUser){ r.dispatchEvent({type:eventOnResult, user:oUser}); // Dispatch the event } } // I may just take this function out all together since the event can // autommatically send them the data. public function getUserData():Object{ return userData; } } Then in your other class you can do something like: //myAdminData is an instance of the class above var r = this; r.eventOnResult= function(evtObj:Object){ trace(user: + evtObj.user); // Should return the oUser object } // addEventListener takes the event name, and who you want to listen myAdminData.addEventListener(eventOnResult, r); Does that help? I obviously can't test the code, but I think everything is right... I have trouble with scope, which is why I use a lot of 'r' values instead of 'this'... Just easier for me... Probably not a good coding standard :) -Dan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Friday, February 16, 2007 9:03 AM To: Flashcoders mailing list Subject: [Flashcoders] Events for custom classes? OK, I'm pretty good at Actionscript 2.0, but something I never really understood and now need to. Core question: How do I make an event in a custom class, and how do I make a listener in another class listen for the event? EventBroadcaster in the help docs seems to only show how to use it with Adobe classes and components. Docs on listener are the same. I know how to set up listeners for other events, like keypresses and mouse rollovers. Easy enough. But my problem is this (see comments in code below): class com.boa.projects.iqrcgenerator.components.AdminData{ private var userData:Object; public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); getUserListResult.onResult = function(oUser){ //this works fine, //I can capture this event result here, //but how do I notify another class? //also what about scope here? //how to set userData as oUser result? //can I fire an event in my AdminData //class from here? } } public function
RE: [Flashcoders] Events for custom classes?
Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object } } Now you have them both communication the way you want Have fun ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 14:36 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B - I'm confused about that. Thanks for any help. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February 16, 2007 10:36 AM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions private var userData:Object; // I'm sure you have a different constructor, but you need // to add that line to it if you want to use the eventdispatcher public function AdminData(){ mx.events.EventDispatcher.initialize(this); // add this to constructor } public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); var r = this; // To get this in onResult getUserListResult.onResult = function(oUser){ r.dispatchEvent({type:eventOnResult, user:oUser}); // Dispatch the event } } // I may just take this function out all together since the event can // autommatically send them the data. public function getUserData():Object{ return userData; } } Then in your other class you can do something like: //myAdminData is an instance of the class above var r = this; r.eventOnResult= function(evtObj:Object){ trace(user: + evtObj.user); // Should return the oUser object } // addEventListener takes the event name, and who you want to listen myAdminData.addEventListener(eventOnResult, r); Does that help? I obviously can't test the code, but I think everything is right... I have trouble with scope, which is why I use a lot of 'r' values instead of 'this'... Just easier for me... Probably not a good coding
RE: [Flashcoders] Events for custom classes?
do you have a reference to the class that is broadcasting the event in the class that's listening for the event? Yes, that's this part of his code: myAdminData.addEventListener(eventOnResult, r); Where he has r = this in his code Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
Thanks Alain, will revist it that way instead. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 3:01 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object } } Now you have them both communication the way you want Have fun ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 14:36 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B - I'm confused about that. Thanks for any help. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February 16, 2007 10:36 AM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions private var userData:Object; // I'm sure you have a different constructor, but you need // to add that line to it if you want to use the eventdispatcher public function AdminData(){ mx.events.EventDispatcher.initialize(this); // add this to constructor } public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); var r = this; // To get this in onResult getUserListResult.onResult = function(oUser){ r.dispatchEvent({type:eventOnResult, user:oUser}); // Dispatch the event } } // I may just take this function out all together since the event can // autommatically send them the data. public function getUserData():Object{ return userData; } } Then in your other class you can do something like: //myAdminData is an instance of the class above var r = this; r.eventOnResult= function(evtObj:Object){ trace(user: + evtObj.user); // Should return the oUser object } // addEventListener takes the event name, and who you want to listen
RE: [Flashcoders] Events for custom classes?
I think Matthew has what you are looking for. Alain's solution should do what you want too. If you want to write two classes with lower cohesion so they aren't referencing each other, you could write a third control class which would have code similar to the following. This way objA and objB don't need to know about each other. If another class needs to start listening for results of the webservices, you add it in here, rather than making changes to your other classes. Class controller { Var objA = new ClassA(); Var objB = new ClassB(); this.eventComboBoxChanged = function(){ // execute functions on B } this.eventWebserviceResultsRecieved = function(){ // execute fuctions on B } this.eventDataRequested = function(){ // execute functions on A } objA.addEventListener(eventComboBoxChanged, this); objA.addEventListener(eventWebserviceResultsRecieved, this); objB.addEventListener(eventDataRequested, this); } Again, I haven't tested this code, but the basic idea should work as long as objA and objB are dispatching the events when the changes occur. ~Dan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Matthew Ganz Sent: Friday, February 16, 2007 1:48 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] Events for custom classes? do you have a reference to the class that is broadcasting the event in the class that's listening for the event? meaning, when you write your addEventListener in your Receiving class, you should have: referenceToBroadcastingClass.addEventListener(myEvent,myHandler); - Original Message - From: Merrill, Jason [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Friday, February 16, 2007 2:35 PM Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B - I'm confused about that. Thanks for any help. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February 16, 2007 10:36 AM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions private var userData:Object; // I'm sure you have a different constructor, but you need // to add that line to it if you want to use the eventdispatcher public function AdminData(){ mx.events.EventDispatcher.initialize(this); // add this to constructor } public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); var r = this; // To get this in onResult getUserListResult.onResult = function(oUser){ r.dispatchEvent({type:eventOnResult, user:oUser}); // Dispatch the event } } // I may just take this function out all together since the event can // autommatically send them the data. public function getUserData():Object{ return userData; } } Then in your other class you can do something like: //myAdminData is an instance of the class above var r = this; r.eventOnResult= function(evtObj:Object){ trace(user: + evtObj.user); // Should return the oUser object } // addEventListener takes the event name, and who you want to listen myAdminData.addEventListener(eventOnResult, r); Does that help? I obviously can't test
RE: [Flashcoders] Events for custom classes?
Hi Jason, I have my own implementation of AsBroadcaster/EventDispatcher (bundling both in one class), which is very flexible and can be used with inheritance or composition (But unlike the standard implementations, it's not a mix-in class). If you'd like me to send you the class, just let me know. Karina -Original Message- From: Merrill, Jason [mailto:[EMAIL PROTECTED] Sent: 16 February 2007 20:16 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Thanks Alain, will revist it that way instead. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 3:01 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object } } Now you have them both communication the way you want Have fun ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 14:36 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B - I'm confused about that. Thanks for any help. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February 16, 2007 10:36 AM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions private var userData:Object; // I'm sure you have a different constructor, but you need // to add that line to it if you want to use the eventdispatcher public function AdminData(){ mx.events.EventDispatcher.initialize(this); // add this to constructor } public function wsUserDataByLOB(lobDbId:Number):Void{ var getUserListResult:Object = new Object(); getUserListResult = generatorWebService.GetUserList(lobDbId); var r = this; // To get this in onResult getUserListResult.onResult = function(oUser){ r.dispatchEvent({type:eventOnResult
RE: [Flashcoders] Events for custom classes?
I think Matthew has what you are looking for. Alain's solution should do what you want too. Thanks Daniel - nice approach, I like it. It's always the design patterns stuff that kills me. I've read a lot about them, but it's hard to know how to apply to specific projects sometimes, so I do a lot of tight-coupled composition type coding sometimes - not the best approach though. Trying to separate model and view here, but the event stuff is stuff I just really need a handle on. Thanks for the samples! There was a Matthew that posted something? ( I only see posts from you, John, Helen, Alain) I must have missed it or deleted it already. Can you send his post offlist to me? Thanks Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
Sure, yes - please send offlist . Thanks! Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Karina Steffens Sent: Friday, February 16, 2007 3:30 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Hi Jason, I have my own implementation of AsBroadcaster/EventDispatcher (bundling both in one class), which is very flexible and can be used with inheritance or composition (But unlike the standard implementations, it's not a mix-in class). If you'd like me to send you the class, just let me know. Karina -Original Message- From: Merrill, Jason [mailto:[EMAIL PROTECTED] Sent: 16 February 2007 20:16 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Thanks Alain, will revist it that way instead. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 3:01 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object } } Now you have them both communication the way you want Have fun ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 14:36 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B - I'm confused about that. Thanks for any help. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February 16, 2007 10:36 AM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions private var userData:Object; // I'm sure you have a different constructor, but you need // to add that line to it if you want to use the eventdispatcher public function AdminData(){ mx.events.EventDispatcher.initialize(this); // add this to constructor } public function
RE: [Flashcoders] Events for custom classes?
Can you please email your class to me as well [offlist]. I'm working on almost the same thing as Jason. Thanks much, Andrew Rost IDEXX Computer Systems -Original Message- From: Merrill, Jason [mailto:[EMAIL PROTECTED] Sent: Friday, February 16, 2007 2:41 PM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Sure, yes - please send offlist . Thanks! Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Karina Steffens Sent: Friday, February 16, 2007 3:30 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Hi Jason, I have my own implementation of AsBroadcaster/EventDispatcher (bundling both in one class), which is very flexible and can be used with inheritance or composition (But unlike the standard implementations, it's not a mix-in class). If you'd like me to send you the class, just let me know. Karina -Original Message- From: Merrill, Jason [mailto:[EMAIL PROTECTED] Sent: 16 February 2007 20:16 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Thanks Alain, will revist it that way instead. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 3:01 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object } } Now you have them both communication the way you want Have fun ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 14:36 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B - I'm confused about that. Thanks for any help. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February 16, 2007 10:36 AM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions
RE: [Flashcoders] Events for custom classes?
Alain, Been following your suggested method, it's great, and everything works as advertized, except can't get wsResulthandler to fire once the Webservice data is received. Also, how do I send the data from the comboBox change event through to the getWsData function? I need to know the data from the selected item in the combobox, as that is a parameter I sent to the webservice to get the data. I hard coded it a number for now, but it doesn't work because of the first problem. Here is a snippet of the code in Class B function getWSdata(lobDbId:Number) { var getUserListResult:Object = new Object(); getUserListResult = root_mc.generatorWS.GetUserList(1) //lobDbId); getUserListResult.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { _level0.traceMsg(WS Result recieved.) this.dispatchEvent({type:webServiceResult, newData:data}) } Did I set that up right? Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 3:01 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object } } Now you have them both communication the way you want Have fun ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 14:36 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B - I'm confused about that. Thanks for any help. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February 16, 2007 10:36 AM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Here is your code modified to use the EventDispatcher: import mx.events.EventDispatcher; // import the event dispatcher class com.boa.projects.iqrcgenerator.components.AdminData{ public var addEventListener:Function; // Set the functions public var removeEventListener:Function; // Set the functions private var dispatchEvent:Function; // Set the functions private var userData:Object; // I'm sure you have a different constructor, but you need // to add that line to it if you want to use the eventdispatcher public function AdminData
RE: [Flashcoders] Events for custom classes?
Nevermind the second part of the question about passing the combobox data, I figured that out: (in class A) function cbChangeHandler(e){ var t_cb:ComboBox = e.target; var thisData:Number = t_cb.dataProvider[t_cb.selectedIndex].data; adminData.getWSdata(thisData); } But the first part of my question regarding getting wsResulthandler to fire once the Webservice data is received is still an issue. Any ideas? Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Friday, February 16, 2007 4:37 PM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Alain, Been following your suggested method, it's great, and everything works as advertized, except can't get wsResulthandler to fire once the Webservice data is received. Also, how do I send the data from the comboBox change event through to the getWsData function? I need to know the data from the selected item in the combobox, as that is a parameter I sent to the webservice to get the data. I hard coded it a number for now, but it doesn't work because of the first problem. Here is a snippet of the code in Class B function getWSdata(lobDbId:Number) { var getUserListResult:Object = new Object(); getUserListResult = root_mc.generatorWS.GetUserList(1) //lobDbId); getUserListResult.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { _level0.traceMsg(WS Result recieved.) this.dispatchEvent({type:webServiceResult, newData:data}) } Did I set that up right? Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 3:01 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object } } Now you have them both communication the way you want Have fun ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 14:36 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B - I'm confused about that. Thanks for any help. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Holth, Daniel C. Sent: Friday, February
RE: [Flashcoders] Events for custom classes?
Jason, By the look of it, you will never receive an onResult for your getUserListResult ... it's a simple Object and no Method onResult exists for that class that I know of ... What are you using to make your webservice calls ? are you using Flash Remoting ? if so you should use the responder to handle the result. import mx.remoting.Service; import mx.remoting.PendingCall; import mx.rpc.RelayResponder; import mx.rpc.FaultEvent; import mx.rpc.ResultEvent; var myService:Service = new Service( gatewayUrl , null , serviceName , null, null ); var pc:Pendingcall = new PendingCall(); pc.relayResponder(myService, handleResult, handleError); well I can't really remember from the top of my head, I'll need to look it up from home, but this is somewhat how you can know when the data has arrived from the webservice. So your class be ends up beeing a Service caller, you can make it a Singleton and use it to fetch different services from your gateway. You should definitely look into the ARP framework (or other similar projects) ... that's how I learned how to best use Design Paterns :) after 2 projets with it, you'll definitely understand :) HTH ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 16:37 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Alain, Been following your suggested method, it's great, and everything works as advertized, except can't get wsResulthandler to fire once the Webservice data is received. Also, how do I send the data from the comboBox change event through to the getWsData function? I need to know the data from the selected item in the combobox, as that is a parameter I sent to the webservice to get the data. I hard coded it a number for now, but it doesn't work because of the first problem. Here is a snippet of the code in Class B function getWSdata(lobDbId:Number) { var getUserListResult:Object = new Object(); getUserListResult = root_mc.generatorWS.GetUserList(1) //lobDbId); getUserListResult.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { _level0.traceMsg(WS Result recieved.) this.dispatchEvent({type:webServiceResult, newData:data}) } Did I set that up right? Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 3:01 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object } } Now you have them both communication the way you want Have fun ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 14:36 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all
RE: [Flashcoders] Events for custom classes?
I am using the Webservice component. It has a built-in onResult event, and works fine for me. But can't get it to work with Delegate. This works for me: var getUserResult = new Object(); getUserResult =alreadyLodedWwebserive.DoMethod(arg) getUserResult.onResult = function(result){ //This works fine for me //I see the data returned here fine. } Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 5:09 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, By the look of it, you will never receive an onResult for your getUserListResult ... it's a simple Object and no Method onResult exists for that class that I know of ... What are you using to make your webservice calls ? are you using Flash Remoting ? if so you should use the responder to handle the result. import mx.remoting.Service; import mx.remoting.PendingCall; import mx.rpc.RelayResponder; import mx.rpc.FaultEvent; import mx.rpc.ResultEvent; var myService:Service = new Service( gatewayUrl , null , serviceName , null, null ); var pc:Pendingcall = new PendingCall(); pc.relayResponder(myService, handleResult, handleError); well I can't really remember from the top of my head, I'll need to look it up from home, but this is somewhat how you can know when the data has arrived from the webservice. So your class be ends up beeing a Service caller, you can make it a Singleton and use it to fetch different services from your gateway. You should definitely look into the ARP framework (or other similar projects) ... that's how I learned how to best use Design Paterns :) after 2 projets with it, you'll definitely understand :) HTH ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 16:37 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Alain, Been following your suggested method, it's great, and everything works as advertized, except can't get wsResulthandler to fire once the Webservice data is received. Also, how do I send the data from the comboBox change event through to the getWsData function? I need to know the data from the selected item in the combobox, as that is a parameter I sent to the webservice to get the data. I hard coded it a number for now, but it doesn't work because of the first problem. Here is a snippet of the code in Class B function getWSdata(lobDbId:Number) { var getUserListResult:Object = new Object(); getUserListResult = root_mc.generatorWS.GetUserList(1) //lobDbId); getUserListResult.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { _level0.traceMsg(WS Result recieved.) this.dispatchEvent({type:webServiceResult, newData:data}) } Did I set that up right? Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 3:01 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object } } Now you have them both communication the way you want Have fun ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 14:36 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when
RE: [Flashcoders] Events for custom classes?
Ah - nevermind - figured out I had removed the scope to my webservice and forgot to put it back in. Delegate works fine for me now, sorry about the noise, and thanks so much everyone for the help!! Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Friday, February 16, 2007 5:18 PM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? I am using the Webservice component. It has a built-in onResult event, and works fine for me. But can't get it to work with Delegate. This works for me: var getUserResult = new Object(); getUserResult =alreadyLodedWwebserive.DoMethod(arg) getUserResult.onResult = function(result){ //This works fine for me //I see the data returned here fine. } Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 5:09 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, By the look of it, you will never receive an onResult for your getUserListResult ... it's a simple Object and no Method onResult exists for that class that I know of ... What are you using to make your webservice calls ? are you using Flash Remoting ? if so you should use the responder to handle the result. import mx.remoting.Service; import mx.remoting.PendingCall; import mx.rpc.RelayResponder; import mx.rpc.FaultEvent; import mx.rpc.ResultEvent; var myService:Service = new Service( gatewayUrl , null , serviceName , null, null ); var pc:Pendingcall = new PendingCall(); pc.relayResponder(myService, handleResult, handleError); well I can't really remember from the top of my head, I'll need to look it up from home, but this is somewhat how you can know when the data has arrived from the webservice. So your class be ends up beeing a Service caller, you can make it a Singleton and use it to fetch different services from your gateway. You should definitely look into the ARP framework (or other similar projects) ... that's how I learned how to best use Design Paterns :) after 2 projets with it, you'll definitely understand :) HTH ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 16:37 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Alain, Been following your suggested method, it's great, and everything works as advertized, except can't get wsResulthandler to fire once the Webservice data is received. Also, how do I send the data from the comboBox change event through to the getWsData function? I need to know the data from the selected item in the combobox, as that is a parameter I sent to the webservice to get the data. I hard coded it a number for now, but it doesn't work because of the first problem. Here is a snippet of the code in Class B function getWSdata(lobDbId:Number) { var getUserListResult:Object = new Object(); getUserListResult = root_mc.generatorWS.GetUserList(1) //lobDbId); getUserListResult.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { _level0.traceMsg(WS Result recieved.) this.dispatchEvent({type:webServiceResult, newData:data}) } Did I set that up right? Thanks, Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 3:01 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object
Re: [Flashcoders] Events for custom classes?
You should really look into something like ARP or Cairngorm. http://osflash.org/arp http://labs.adobe.com/wiki/index.php/Cairngorm regards, Muzak - Original Message - From: Merrill, Jason [EMAIL PROTECTED] To: Flashcoders mailing list flashcoders@chattyfig.figleaf.com Sent: Friday, February 16, 2007 9:40 PM Subject: RE: [Flashcoders] Events for custom classes? I think Matthew has what you are looking for. Alain's solution should do what you want too. Thanks Daniel - nice approach, I like it. It's always the design patterns stuff that kills me. I've read a lot about them, but it's hard to know how to apply to specific projects sometimes, so I do a lot of tight-coupled composition type coding sometimes - not the best approach though. Trying to separate model and view here, but the event stuff is stuff I just really need a handle on. Thanks for the samples! There was a Matthew that posted something? ( I only see posts from you, John, Helen, Alain) I must have missed it or deleted it already. Can you send his post offlist to me? Thanks Jason Merrill Bank of America Learning Organizational Effectiveness ___ 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] Events for custom classes?
I sent the custom class off list to both of you. If anyone else is interested, I'll put it on my blog as soon as I get a moment to spare, and will let the list know when it's there. Karina -Original Message- From: Rost, Andrew [mailto:[EMAIL PROTECTED] Sent: 16 February 2007 20:55 To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Can you please email your class to me as well [offlist]. I'm working on almost the same thing as Jason. Thanks much, Andrew Rost IDEXX Computer Systems -Original Message- From: Merrill, Jason [mailto:[EMAIL PROTECTED] Sent: Friday, February 16, 2007 2:41 PM To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Sure, yes - please send offlist . Thanks! Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Karina Steffens Sent: Friday, February 16, 2007 3:30 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Hi Jason, I have my own implementation of AsBroadcaster/EventDispatcher (bundling both in one class), which is very flexible and can be used with inheritance or composition (But unlike the standard implementations, it's not a mix-in class). If you'd like me to send you the class, just let me know. Karina -Original Message- From: Merrill, Jason [mailto:[EMAIL PROTECTED] Sent: 16 February 2007 20:16 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Thanks Alain, will revist it that way instead. Jason Merrill Bank of America Learning Organizational Effectiveness -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Rousseau Sent: Friday, February 16, 2007 3:01 PM To: 'Flashcoders mailing list' Subject: RE: [Flashcoders] Events for custom classes? Jason, So if I understand clearly what you want to do is : From Class A : (pseudo code following) class ClassA { private var instClassB:ClassB; make comboBox make datagrid function ClassA() { instClassB = new ClassB(); comboBox.onChange = Delegate.create(this, cbChangeHandler); instClassB.addEventListener(webServiceResult, this); } function cbChangeHandler(e){ instClassB.getWSdata(e.value); } function webServiceResult(evtObj:Object) { update datagrid with evtObj.newData } } class ClassB { Decorate with EventDispatcher methods dispatchEvent, addEventListener, removeEventListener function ClassB() { EventDispatcher.initialize(this); } function getWSdata(val) { get data from web service wsInstance.onResult = Delegate.create(this, wsResulthandler); } function wsResulthandler(data) { this.dispatchEvent({type:webServiceResult, newData:data}) // add anything you want to pass in the object } } Now you have them both communication the way you want Have fun ! Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: 16 février 2007 14:36 To: Flashcoders mailing list Subject: RE: [Flashcoders] Events for custom classes? Daniel, try as I may, I can't get your code to work. I have one class, which has a combobox. I can get the event to fire when the combobox changes just fine, but I can't get it to hear the firing of the data capture from the webservice in the other class. So basically, in pseudocode, I need to do this: class A{ make comboBox make datagrid when comboBox changes, use Class B to get data from webservice when webservice result received, update datagrid with new data } class B{ connect to webservice when requested, return data to requesting class } Reason I want these two classes to be separate is because I want other classes to call Class B to get data as well. So, I can do all of those things just fine, they are all working, except for the last part, when requested, return data to requesting class - I figure since the webservice is asynchronous, I need to capture the received event, which is fine, I can do, that works. But I need to tell Class A to update the datagrid with the new data when it gets it from Class B - so an event model is required. in your code, you have a var r in both the Class A and Class B