In an effort to simplify chaining of events within the pureMVC framework, I created a small utility based upon a mediator.
Its purpose is to accept a list of notifications in the order in which you would like them to be processed.
As the Chain Notifier is asynchronous
it can be used for transitions or server-side communication, it merely responds to user defined notifications before moving to the next link in its chain keeping things simple and in one place.
In this example the Chain Notifier is within the execution body of a command.
but could be setup where ever you load your mediators.ApplicationFacade
override protected function initializeController( ) : void StageInitializedCommand
registerCommand( STARTUP, StartUpCommand );
registerCommand( STAGE_INITIALIZED, StageInitializedCommand );
public class StageInitializedCommand extends SimpleCommand
* Register the Proxies.
override public function execute( note:INotification ) :void
// Register the chainNotifier Mediator and establish chain linkages.
var chainNotifier:ChainNotifier = new ChainNotifier();
chainNotifier.AddNode( ApplicationFacade.SPLASH_SHOW, ApplicationFacade.SPLASH_INITIALIZED, note.getBody() ); //include note for startup
chainNotifier.AddNode( ApplicationFacade.PROGRESSBAR_SHOW, ApplicationFacade.PROGRESSBAR_INITIALIZED);
chainNotifier.AddNode( ApplicationFacade.LOGIN_SHOW, ApplicationFacade.LOGIN_INITIALIZED);
facade.registerMediator( chainNotifier ); //onRegister will start first notification
In my example the note.Body was supplied so my splash screen would have a stage VO.
the SPLASH_INITIALIZED notification is what triggers the next link ie: PROGRESSBAR_SHOW and so on.
obviously the last one LOGIN_INITIALIZED does not have anthing to trigger and so is a little superfluous.. :-)SplashCanvasMediator
using chain notification
override public function handleNotification( note:INotification ):void
var stageVO:StageVO = note.getBody() as StageVO;
switch ( note.getName() )
//sendNotification will cause chain to next() using canvas as body for next chain link
canvas.init(stageVO.screenW, stageVO.screenH, styleProxy.style);
this.sendNotification( ApplicationFacade.SPLASH_INITIALIZED, canvas );
as it integrates into the framework using notifications the ChainNotifier can be dropped in place with a minimal of effort and helps maintain a loosely coupled system.Syntax Overview:
Main ChainNotifier ConstructorFlow Overview:
the class is conceptually a asynchronous queuing system referred to as a chain
transition between nodes (links) is controlled through the use of notifications inthe pureMVC framework
You can choose to override the default generated action trigger notifications names if needed, but should not be needed
Base action names are appended to the Mediator name to insure unique action names for any givin ChainNotifier
in this example , ChainNotifier("MYCHAINNAME"); ... would yeld MYCHAINNAME_ACTION_START, MYCHAINNAME_ACTION_STOP .. etc
public function ChainNotifier( qname:String,
qsetactive:String="_ACTION_SETACTIVE" ) :void
eg: var chainNotifier:ChainNotifier = new ChainNotifier("MYCHAINNAME");
@param qname - name of chain, If using defaults this name will be added to Action notification names
@param qstart - Action start at the beginning of the queue and send first initial notification
@param qstop - Action pause at current queue position, receiving of notifications except Actions, will be paused
@param qcontinue - Action continue from pause position,activation of notifications will be enabled
@param qend - Action skip to end node and send notification
@param qnext - tAction node Move to nextAction Node and send notification , default behavior
@param qprev - Action node Move back and repeat send notification
@param qclear - Action will remove all nodes in array and free memory (no resart from this unless addNode/addAction is used
@param qsetactive - experimental,not yet implemented with notifications however, can be triggered as method on the class
Active/Inactive will skip Inactive Nodes
* Notes: note.Body() and noteType() are sent to next link from prev notifyListener
* Start will override all commands (pause, continue)
* All Actions can be activated through the use of notifications and notification names overridden at constructor time
* onRegister will start first notification, if you addNodes after this you will need to Start()
This function provides the main method for sequentially adding notifications
when its notifyListener notification is recived it moves to the next in the chain.
This nex link then emits its notifySender notifications and waits for ITS notifyListener
If you wish to use commands, simply register your commands to take the chain links notifySender.
when the command is called, at some point, either in the command or what the command is activating will
need to send notification for the chain to be moved to next next point.
eg. addNode( ApplicationFacade.SPLASH_SHOW, ApplicationFacade.SPLASH_INITIALIZED, note.getBody() ,note.getType());
optional note.getBody() ,note.getType() can be set for the first Node to pass through, to the next node in the chain
otherwise body and type are used from the received notifyListener and passed through to the next node in the chain
@param notifySender - the notification you wish to send when this link in the chain is triggered
@param notifyListener - the notification this link will listen for to move to next link in chain
@param body - an optional notification body object to pass ( default is previous links notification body)
@param type - and optional notification type string to pass ( default is previous links notification type)
@param active - to set a node inactive or active (testing whether this is useful) ( maybe placed before node function in a different release )
This function provides a method to add Function callbacks triggered by notifications
The Class uses this internaly for adding the default Actions
Although this is a little outside the box of its intended use it does provide a powerful
triggering mechanism from within PureMVC the framework
eg. addAction( "MY_ACTION_NOTIFICATION", myFunction);
myFunction(node:ChainNotifierNode=null):void //function prototype for any addAction
@param notifyListener - the notification this Action will listen for to call nFunction
@param nFunction - the function to call when triggered by notifyListener notifications
The constructor sets up Action notifications that can be used to control internal ChainNotifier behavior (if needed)
AddNode creates a node within the ChainNotifier supplying its name and start/next notification scheme.
OnRegister generates the first Action (if addNode
includes a note body this is also sent with the notification)
register interest in the current index and Actions.
Upon receiving handleNotification
either an Action is issued or the chain is moved to the next item and notification sent
In its basic operation it should not be necessary to use Actions
, only if you want to get fancy or controll chain other next()installation
Simply copy the code into your view area and replace package naming
The code was designed using multi-core but can be replaced easily to standard (remove multicore name)
Comments or suggestions are welcome, if developers feel this is a worthy tool to be included I'll work with Cliff to create repository and package accordingly (as a utility)Zip FileLatest Versionhttp://www.trilec.com/opensource/ChainNotifier_1.2.zipPrevious http://www.trilec.com/opensource/ChainNotifier_1.1.ziphttp://www.trilec.com/opensource/ChainNotifier_1.0.zip
EDIT1: Removed Superfluous Naming and Added SetActive(), a few optimizations and added passing of getType()
EDIT2: AddNode documentation ,
EDIT3: Action Wording change in Docs and Code, Cliffs notes addressed
EDIT4: Version update, better wording of examples