I make flash games with a standardized UI. There are dozens of different *.fla files of different games, created at different times, and all them should share the same interface. My solution was to put this interface into a Library.swf and make every game load that file first and initialize the required classes. It worked perfectly.
Now, the UI and the game had to exchange events. If the “Next” button in the UI is clicked, the game has to know it. The solution was create an InterfaceEvent class. The game calls
ui.addEventListener(InterfaceEvent.BTN_NEXT_CLICKED, desiredFunction)
and the UI dispatches
dispatchEvent(new InterfaceEvent(InterfaceEvent.BTN_NEXT_CLICKED))
It also works.
Then I had to add a new type of event for a new button. I simply added an extra constant at the InterfaceEvent class and created the code to dispatch it when needed. And the problem appeared.
The game had a version of the InterfaceEvent, the one that was present when the game was compiled. The Library.swf has a different version, with an added constant, because it was compiled later.
Now, when the Library is loaded, the game’s version of the class **overrides **the library’s, as if it was “already in cache”. This leads to numerous “cannot dispatch an event with a null type”, because the game’s version does not have the required constant.
My question is: is there a way to control this overlapping without using a separated class for each side? Using a LibraryInterfaceEvent and GameInterfaceEvent is possible because new events will only be added, never removed, but that does not look very elegant.