Re-dispatching event in FLEX

In a FLEX app, I am trying to "re-dispatch" a custom event. I.e. component1 does dispatchEvnet(event), component2 registers a handler for the event, the only function of the handler being, again, dispatch(event). Finally, component3 listens for the event coming out of component2. What I am trying to do is similar to the concept of "re-throwing" exceptions (and for similar reasons). The difference is that re-dispatching does not seem to work in AS3 (Flash 10). In IE, nothing happens, and in FF3 there is an exception saying that the type cast failed while trying to coerce the Event type to my CustomEvent while calling the handler in component3. Tracing code in the debugger shows that by the time component3 is called, the event is, indeed, a generic one, with all my custom stuff lost. Is this supposed to be the case?


The problem you are experiencing is caused by not overriding the clone() event in your custom event.

When events are redispatched, they are cloned and modified. If you don't override clone() you get the base implementation of clone(), which returns an Event. Because Event cannot be cast to your custom event type, a runtime error is thrown.

From the documentation:

When creating your own custom Event class, you must override the inherited Event.clone() method in order for it to duplicate the properties of your custom class. If you do not set all the properties that you add in your event subclass, those properties will not have the correct values when listeners handle the redispatched event.

more see:

Need Your Help

How do I distinguish Simplified and Traditional Chinese in C#?

.net localization internationalization cjk iso

My app has been translated to a number of languages, including French, Traditional Chinese, and Simplified Chinese. Now, when the app first launches, I'd like to automatically select the correct

STL Map throwing an error upon search attempt

c++ string stl maps

I am trying to create a map full of strings as keys and integers as values. The problem begins when I try and search with it. Can someone tell me where I went wrong? Is it that I have two Maps i...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.