ActionScript 3.0

Mate… Lightweight Schedule Extension

Some time ago I was in need of something to be run at regular intervals.
Among the many implementations I already had in my framework, I thought that including either my Workflow package (An ActionScript port of the Windows Workflow Foundation 3) or my processing package (eventually just a scheduling application block which allows processes to be managed Windows Service style.

I wanted something much more lightweight, so I decided to implement a Schedule Handler.
It extends the AbstractHandlers class, so all I had to do was initiate a timer and then run the sequence when the timer elapsed… more lightweight then that is hard to imagine.


package org.hellogroup.mate.actionLists
{
	import com.asfusion.mate.actionLists.AbstractHandlers;
	import com.asfusion.mate.actionLists.Scope;

	import flash.events.TimerEvent;
	import flash.utils.Timer;

	public class Schedule extends AbstractHandlers
	{
		private var timer:Timer = null;

		public function Schedule()
		{
			super();

			this.timer = new Timer( 1000 );
			this.timer.addEventListener( TimerEvent.TIMER, this.handleTimer );
		}

		[Bindable]
		public function get delay() : Number
		{
			return timer.delay;
		}

		public function set delay( value:Number ) : void
		{
			this.timer.delay = value;
		}

		override public function initialized( document:Object, id:String ) : void
		{
			super.initialized( document, id );

			this.timer.start();
		}

		private function handleTimer( event:TimerEvent ) : void
		{
			this.runSequence( new Scope( event, true, this.map ), this.actions );
		}
	}
}

The class is included in the downloads in my previous post…
https://blog.petermolgaard.com/2009/05/30/mate-stopanddispatchhandlers-extension/

Advertisements

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