ActionScript 3.0

Mate… StopAndDispatchHandlers Extension

Some time ago I found myself in need of a couple of features not included in Mate, such as a StopHandler which would be interruptable, but instead of just returning from the entire ActionList, would dispatch an event which could be handled by another handler.

It was named StopAndDispatchHandlers and extends the standard StopHandlers.

First I created a somewhat abstract stophandlers class which overrides the run function and handles some of the more intricate details relating to the lastReturnEquals and lastReturn members of the scope object.


package org.hellogroup.mate.actions
{
	import com.asfusion.mate.actionLists.IScope;
	import com.asfusion.mate.actions.StopHandlers;

	public class StopHandlers extends com.asfusion.mate.actions.StopHandlers
	{
		public function StopHandlers()
		{
			super();
		}

		override protected function run( scope:IScope ):void
		{
			super.run( scope );

			if( lastReturnEquals == null && scope.lastReturn == null )
			{
				scope.stopRunning();
			}
		}
	}
}

Here is the concrete implementation which allows for a stophandler to dispatch an event.


package org.hellogroup.mate.actions
{
	import com.asfusion.mate.actionLists.IScope;
	import org.hellogroup.mate.actions.StopHandlers;
	import flash.events.Event;

	public class StopAndDispatchHandlers extends StopHandlers
	{
		private var _nextEvent:Event = null;

		public function StopAndDispatchHandlers()
		{
			super();
		}

		public function get nextEvent() : Event
		{
			return _nextEvent;
		}

		public function set nextEvent( value:Event ) : void
		{
			_nextEvent = value;
		}

		override protected function run( scope:IScope ):void
		{
			super.run( scope );

			scope.dispatcher.dispatchEvent( nextEvent );
		}
	}
}

You can download the compiled binary from here…
http://petermolgaard.com/projects/MateSchedule.swc.zip

…and the entire sourcecode as a Flex project from here…
http://petermolgaard.com/projects/MateSchedule.fxpl.zip

Advertisements

One thought on “Mate… StopAndDispatchHandlers Extension

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s