Event name collisions

hush's Avatar


01 Dec, 2009 12:13 AM

Hello again ;]
I've come up yet with another problem:

[Fault] exception, information=TypeError: Error #1034: Type Coercion failed: cannot convert e3.timeline.events::PlaylistEvent@308d2f59 to e3.timeline.events.JavaScriptEvent.
Fault, routeEventToListener() at EventMap.as:166

Now, the interesting thing is that both classes PlaylistEvent and JavaScriptEvent have an event named "SAVE":

public static const PlaylistEvent.SAVE = "SAVE";
public static const JavaScriptEvent.SAVE = "SAVE";

PlaylistEvent.SAVE is mapped to a command:

commandMap.mapEvent(PlaylistEvent.SAVE, SavePlaylistCommand, PlaylistEvent);

JavaScriptEvent.SAVE is mapped to a mediator's function:

eventMap.mapListener(eventDispatcher, JavaScriptEvent.SAVE, onSavePlaylist);

The event flow is as follows:
1. JavaScript executes save function on flash object
2. Save function has got a callBack function in JavaScriptService which then dispatches system event JavaScriptEvent.SAVE
3. This event is cought by AppMediator which in turn samples some data on its view and dispatches a different system event called PlaylistEvent.SAVE.
4. The error occurs.
5. !!! Changing the string name of one of the events fixes the problem which makes me think of event name collisions.
Any opinions on this? Thanks a lot for your time! ;]

  1. 1 Posted by derekdon on 01 Dec, 2009 01:03 AM

    derekdon's Avatar

    It's an event name collision from initial glance. Both constants have the same value of "SAVE".

    I'm sure others may have an opinion on this, but I use the following naming convention to avoid this problem...

    public class PaletteEvent
    extends Event
        public static const OPEN:String = "PaletteEvent.OPEN";
        public static const EXPAND:String = "PaletteEvent.EXPAND";
        public static const COLLAPSE:String = "PaletteEvent.COLLAPSE";

    A similar approach may solve your problem.

  2. Support Staff 2 Posted by Shaun Smith on 02 Dec, 2009 08:17 AM

    Shaun Smith's Avatar

    It's a collision. You could use the naming technique suggested above, or preferably:

    Use the 4th parameter of mapListener to ensure that your listeners only respond to events of the correct class.

  3. Shaun Smith closed this discussion on 02 Dec, 2009 08:17 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac