On Tue, Jan 13, 2009 at 8:09 PM, Dan <[email protected]> wrote:
> I think you are right. Since Event is represented by object, I thought
> you could create event handlers in polymorphic manner, just like when
> handling errors, when you write catch(e:MyErrorClass). Such catch
> would also handle MyChildErrorClass error. It seems that this does not
> work with events….
Well, you can use the same event "type" but with a different class. So
let's say your base event class is MyEvent. The event type is
"myEvent". You listen to the event like so:
someObj.addEventListener(MyEvent.MY_EVENT, myEventHandler);
Your myEventHandler looks like this:
function myEventHandler(event:MyEvent):void
{
...
}
Now, so long as the type of the event object is MyEvent, your
myEventHandler should be able to execute without any problems. So the
author of someObj could write their own event class, say
SomeOtherEvent, like so:
public class SomeOtherEvent extends MyEvent {
public function SomeOtherEvent(...) {
super(...);
// custom properties, etc.
}
// custom properties
}
And they could dispatch the event:
someObj.dispatchEvent(new SomeOtherEvent(MyEvent.MY_EVENT, ...));
And your handler, myEventHandler, will be able to handle it perfectly
well. Isn't that what you're looking for?
Manish
--
http://manishjethani.com
------------------------------------
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Alternative FAQ location:
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo!
Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[email protected]
mailto:[email protected]
<*> 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/