Pascal ECHEMANNI'm an ActionScript developer in the French Riviera.
I've created the Swing Package for ActionScript 3.0 (SPAS 3.0) which helps Flash developers to easily create RIAs with the Flash Platform and both Flash and Flex:
http://www.flashapi.org/ View all articles by Pascal ECHEMANN
8) EventCollector and MVC
When you are designing an object-oriented application, it is not advisable to share functionalities across several different modules. The direct consequence is that sharing an
EventCollector instance, between two or more classes, is not good practice.
However, it is always possible to implement a shared
EventCollector instance in the MVC pattern. But to be efficient, you must follow some basic rules to design the structure of the pattern:
EventCollectorinstance must be a singleton.
- The MVC pattern should be considered as a module itself. It means that
EventCollectorsingleton must not be used by an object which does not belong to this module. (Principle of Retention of Information.)
removeAllEvents()method must be the first action called within the destroying method implemented by the model. So, the structure of events management inside each object must be designed to respect this rule. (This is based on the principle of Modular Composability.)
Even if it is technically possible to do that, it seems wise to discourage the use of such practices! Unfortunately, the MVC pattern is not the best way to simplify the management of memory leaks. Thus, whatever the considered solution, it will not be easy to implement it.
In any case, you should implement a destroying method each time the rules introduced in Chapter 7 are confirmed.
9) Where to go from here
In this article, we learned how to use the
EventCollector to simplify and improve the management of event handling in ActionScript 3.0. By now, you should be able to implement the
EventCollector API in your existing and new projects by using the concepts explained in Chapter 7.
To be informed of new releases, latest information and documents about the collector API, or support SPAS 3.0 projects, follow us on the SPAS 3.0 Facebook page at: http://www.facebook.com/flashapi
We need your feedback to add functionalities to the collector API, so feel free to post your comments on the page devoted to this article, on the SPAS website at: ActionScript 3.0 Best Practices: Using the EventCollector Class
[MEYER, 1997] Bertrand MEYER, Object-Oriented Software Construction, second edition, Prentice Hall, 1296 pages, January 1997.