awesome! thanks. I am new to the ActionScript 3 Event Model but I see the obvious benefits.
Thanks Again, Eric --- In [email protected], "Danny Patterson" <[EMAIL PROTECTED]> wrote: > > You're not adding the TestHandler object as a listener of the > TestDispatcherClass object. Your code is actually registering to itself. > Also, you probably shouldn't dispatch an event from the constructor, since > that runs before anything else you won't be able to add a listener before > your constructor dispatches the event. Try this: > > package com.test { > import flash.display.Sprite; > import flash.events.Event; > public class TestDispatcherClass extends Sprite { > public function runDispatch() { > dispatchEvent(new Event("action")); > } > } > } > > > package com.test { > import mx.controls.Alert; > import flash.display.Sprite; > import com.test.TestDispatcherClass; > public class TestHandler extends Sprite { > public function TestHandler(dispatcher:TestDispatcherClass) { > dispatcher.addEventListener("action", actionHandler); > } > public function actionHandler(event:Event):void { > Alert.show("hanlded event:" + event.toString()); > } > } > } > > > <mx:Application xmlns:mx="http://www.adobe. <http://www.adobe.com/2006/mxml> > com/2006/mxml" > layout="absolute" xmlns="*" creationComplete="this.initApp();"> > <mx:Script> > <![CDATA[ > import com.test.TestHandler; > import com.test.TestDispatcherClass; > private var test:TestHandler; > private var dispatcher:TestDispatcherClass; > private function initApp():void { > dispatcher = new TestDispatcherClass(); > test = new TestHandler(this.dispatcher); > dispatcher.runDispatch(); > } > ]]> > </mx:Script> > </mx:Application> > > > > _____ > > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of efeminella > Sent: Monday, July 10, 2006 10:12 PM > To: [email protected] > Subject: [flexcoders] Re: Simple Event Listener Examples between 2 classes > > > > Yeah, I have read the documentation for the new event model but I am > having a few issues. Here is a simple example of what I am trying. > Maybe you could give me some insight as to what I am doing wrong: > > package com.test { > > import flash.display.Sprite; > import flash.events.Event; > import com.test.EventManager; > import mx.controls.Alert; > > public class TestDispatcherClass extends Sprite { > > public function TestDispatcherClass() > { > this.dispatchEvent(new Event("action")); > } > } > } > > the class that will handle the event and get data from the dispatcher: > > package com.test { > > import com.test.EventManager; > import flash.events.EventDispatcher; > import flash.events.Event; > import mx.controls.Alert; > import flash.display.Sprite; > > public class TestHandler extends Sprite { > > public function TestHandler() > { > this.addEventListener("action", actionHandler); > } > > public function actionHandler(event:Event):void > { > Alert.show("hanlded event:" + event.toString()); > } > } > } > > .mxml: > <mx:Application xmlns:mx="http://www.adobe. <http://www.adobe.com/2006/mxml> > com/2006/mxml" > layout="absolute" xmlns="*" creationComplete="this.initApp();"> > > <mx:Script> > <![CDATA[ > > import com.test.TestHandler; > import com.test.TestDispatcherClass; > > private var test:TestHandler; > private var dispatcher:TestDispatcherClass; > > private function initApp():void { > this.test = new TestHandler(); > this.dispatcher = new TestDispatcherClass(); > } > ]]> > </mx:Script> > </mx:Application> > > Any Ideas??? > > --- In [EMAIL PROTECTED] <mailto:flexcoders%40yahoogroups.com> ups.com, > "Jeremy Lu" <wade.lu@> wrote: > > > > All your classes can extends flash.events.EventDispatcher then they > can just > > fire a > > > > this.dispatchEvent(new MyEvent(aaa, bbb, ccc)); > > > > other classes can use addEventListener("XMLParsed", someHandler) to > handle > > the event. > > > > or you can take a look at how Cairngorm use Cairngorm Event > dispatcher as a > > cetralized event center to dispatch event for every class. > > > > > > Jeremy. > > > > On 7/11/06, efeminella <efeminella@> wrote: > > > > > > Does anyone have any simple examples of how to dispatch and handle > > > events between 2 classes. For example how can I have a class that > > > loads and parses xml and then dispatch an event which another class > > > handles and the event and displays the data. Sort of like we did in AS > > > 2 with event.target... > > > > > > Thanks in advance, > > > Eric Feminella > > > > > > > > > > > > ------------------------ Yahoo! Groups Sponsor --------------------~--> Check out the new improvements in Yahoo! Groups email. http://us.click.yahoo.com/6pRQfA/fOaOAA/yQLSAA/nhFolB/TM --------------------------------------------------------------------~-> -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

