Ross, The addEventListener would be on the instance of your "different class than the HTMLLoader".
myOtheraClass.addEventListener(MyCustomEventClass.MYCUSTOMEVENT, onMyCustomEvent) Make sense? Jason Merrill Bank of America Instructional Technology & Media · GCIB & Staff Support L&LD Interested in Flash Platform technologies? Join the Bank of America Flash Platform Developer Community Interested in innovative ideas in Learning? Check out the Innovative Learning Blog and subscribe. -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Lehr, Ross (N-SGIS) Sent: Friday, December 19, 2008 9:04 AM To: Flash Coders List Subject: RE: [Flashcoders] Custom eventListener Thanks Jason... Let me ask one question to try to clarify this for me. If I have the dispatchEvent that broadcasts the URL of my HTLMLoader in a onLoadComplete function and I want to listen for that event in a different class (for example I want to put the URL in a textbox that is created in a different class than the HTMLLoader) where would I put the addEventListener? I'm not sure why my head is not wrapping around this, but thanks for all your help. Ross -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Merrill, Jason Sent: Thursday, December 18, 2008 5:20 PM To: Flash Coders List Subject: RE: [Flashcoders] Custom eventListener To add on to David's fine reply, Ross, you're close, but not quite - this is how I write custom events, I think you'll want to do something like this instead - this works great for me: To write the event: package events { import flash.events.Event; public class MyEvent extends Event { public static var MYEVENT1:String = "myEvent1"; public static var MYEVENT2:String = "myEvent2"; public function MyEvent(type:String, bubbles:Boolean = false, cancellable:Boolean = false ) { super(type, bubbles, cancelable); } } } Then to dispatch: import events.MyEvent; dispatchEvent(new MyEvent(MyEvent.MYEVENT2, false, true)); Then to listen and react to dispatch: myObject.addEventListener(MyEvent.MYEVENT2, onMyEvent2) public function onMyEvent2(event:MyEvent):void { Trace("myEvent2 heard!"); } Jason Merrill Bank of America Instructional Technology & Media · GCIB & Staff Support L&LD Interested in Flash Platform technologies? Join the Bank of America Flash Platform Developer Community Interested in innovative ideas in Learning? Check out the Innovative Learning Blog and subscribe. -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of David Hershberger Sent: Thursday, December 18, 2008 4:58 PM To: Flash Coders List Subject: Re: [Flashcoders] Custom eventListener An event is just a message object. Just because one gets created successfully does not mean it is being delivered. dispatchEvent() is a method of the EventDispatcher class, which is a superclass of many classes, including DisplayObject. You need to listen for the event (with addEventListener()) on the same EventDispatcher where the event was dispatched. (Except in the case of events that bubble, but that's another topic.) For example: public class MyWindowHolder extends Sprite { public function init(): void { var a: MyWindow = new MyWindow(); a.addEventListener( MyEvent.EXCLAMATION, onExclamation ); } private function onExclamation( event: MyEvent ): void { trace("ouch!"); } } public class MyWindow extends Sprite { private function injury(): void { this.dispatchEvent( new MyEvent( MyEvent.EXCLAMATION )); } } Hope this helps, Dave On 12/18/08, Lehr, Ross (N-SGIS) <[email protected]> wrote: > > Hey All... > > I'm having trouble with a custom event listener. I'm working on > experiment browser project trying to learn as3, OOP, and AIR. I > broadcasting the URL after a web page is loaded and I need a text box to > listen for it. I've added a trace to me urlLoadedEvent class and I know > the URL is getting there (so, I think it's getting broadcasted ok), but > it's not getting to the text box. I think I have my listener in the > wrong place, but not sure where to put it. I don't have my exact code > here, but below are some code snippets. Thanks for any and all help. > > Ross > > > > ------ DISPACTING EVEN > > In a loadComplete function urlLocation = text field for the URL string > > dispatchEvent(new urlLoadEvent(urlLocation.text)); > > ------ urlLoadEvent Class (when I trace urlLocation I am getting the URL > string) > > package > { > import flash.events.*; > > public class urlLoadEvent extends Event > { > public static const URL_CHANGED = "urlChanged"; > public var urlLocation:String; > > public function urlLoadEvent(urlL:String):void > { > super(URL_CHANGED); > urlLocation = urlL; > trace(urlLocation); > } > > } > } > > ------ I'm not sure where to attach this. > > ???????.addEventListener(urlLoadEvent.URL_CHANGED, onURLChange); > _______________________________________________ > Flashcoders mailing list > [email protected] > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list [email protected] http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

