Yes - thanks Muzak - I can't speak for Helmut, but I've got enough to go on now. Thanks,
Jason Merrill Bank of America GT&O 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: [email protected] >>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: <[email protected]> >>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 >>> GT&O Learning & Leadership Development >>> eTools & Multimedia Team >>> >> >> >>_______________________________________________ >>[email protected] >>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 >> _______________________________________________ [email protected] 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

