---
id: 1389
title: Mate... StopAndDispatchHandlers Extension
slug: mate-stopanddispatchhandlers-extension
date: '2009-05-30T13:48:26Z'
modified: '2009-05-30T13:48:26Z'
status: publish
type: post
author: pmoelgaard
categories:
  - ActionScript 3.0
tags:
  - Code
  - Mate Flex Framework
excerpt: null
canonicalPath: /posts/mate-stopanddispatchhandlers-extension
featuredImage: null
commentCount: 1
wordCount: 233
readingTimeMinutes: 2
hasMedia: false
hasVideos: false
url: 'https://forwardthinking.pemo.me/posts/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.

```jscript

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 &amp;&amp; scope.lastReturn == null )
			{
				scope.stopRunning();
			}
		}
	}
}
```

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

```jscript

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](http://petermolgaard.com/projects/MateSchedule.swc.zip) ...and the entire sourcecode as a Flex project from here... [http://petermolgaard.com/projects/MateSchedule.fxpl.zip](http://petermolgaard.com/projects/MateSchedule.fxpl.zip)
