Events centralization – Centralized Event Management

0 Flares Twitter 0 Facebook 0 Google+ 0 Email -- Filament.io 0 Flares ×

What for ?

Events centralization allows to listen for events of an object that we don’t have direct access to.

Example

We have a button in a MovieClip that is not directly connected to your main MovieClip or class where you want to keep all the events logic. There are many ways to get the reference of your button but if you only need to listen for its events then there is a simple way.

Events centralization

The core of the centralization system is a Singleton (some sort of a class pattern that allows us to have only one instance of a class wherever you instanciate it).
From this Singleton, which is an extension of the "EventDispatcher" class, you will be able to dispatch any event with any object that has an instance of this Singleton. You then only need to listen to the same Singleton class to receive events from any of those objects.

Working example

From the "Button" object, simply dispatch an event through the Singleton class instance. And from the "Child" object where all events logic are handled, just listen to the events through the same Singleton class instance. As simple as this !
You can actually do this with my EventsManager class.

0 Flares Twitter 0 Facebook 0 Google+ 0 Email -- Filament.io 0 Flares ×

Leave a Comment

*