ActionScript 3.0, Adobe Flex

Introducing HydraMVC…

HydraMVC is one of the most recent newcomers to the scene of Application Frameworks and Architecture Blocks for Flex Applications.
Its definitely something I’m going to check out in parallel to my love affair with the Mate Flex Framework.

2009-06-04_1707

HydraMVC is the result of a total rewrite of the PureMVC API exclusively for Flex, allowing Flex developers to take advantage of the PureMVC paradigm while leveraging native Flex features.

In addition to using Events vs. an independent Observer pattern, HydraMVC also streamlines implementation, encapsulating much of the initialization code that needed to be written when implementing PureMVC.

HydraMVC was written out of a love / hate relationship with PureMVC; it’s not our intent to say it’s “better” than PureMVC, because the mission of the frameworks are entirely different. PureMVC intends to be language-agnostic, where HydraMVC is a compromise by design.

While HydraMVC is an MVC framework, the demos also imply a strategy for package structure, although the implementation of HydraMVC will work regardless of whatever package structure convention you use. The goal was to create a structure that scales well for large applications, but it also allows you to quickly develop small applications in a proper MVC.

ActionScript 3.0, Adobe Flex, Tools

FC / FB Workflow Optimizer… sources available

I have made the sources available for the Workflow Optimizer… its a crude implementation but it does the job.
It uses Flex, AIR, as3preferenceslib, as3corelib and the Mate Flex Framework.

Don’t hesitate to comment on the ideas or concepts.. but don’t comment the code: it’s not written with any other priority than functionality…

Check it out…
http://code.google.com/p/workflowoptimizer/

ActionScript 3.0, Tools

Flash Catalyst / Flash Builder Workflow Optimizer

Workflow Optimizer is a small and lightweight tool which helps Flash Designers and Flash Developers to work around some of the temporary limitations with Flash Catalyst.

WorkflowOptimizer

The application allows you to automatically extract the contents of FXP / FXPL files and put them into a configurable directory and can hence replace some of the tedious export / import actions from Flash Catalyst to Flash Builder.

The application is written in Flash Builder 4 with Flex 4 and AIR, it uses the as3preferenceslib for persisting the directory and file information and it uses Mate Flex Framework as the application controller.

Next step is to add support for running as a service by adding some Merapi classes and examine even better ways to help optimize the FC / FB workflow.

You can download and install the latest version from the Adobe AIR Marketplace here…
http://www.adobe.com/cfusion/marketplace/index.cfm?event=marketplace.offering&offeringid=13424

Sources are available at Google Code…
http://code.google.com/p/workflowoptimizer/

You can download the binary from here…
http://petermolgaard.com/projects/workflowoptimizer/WorkflowOptimizer.air.zip

Sources will soon follow…

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…
http://blog.petermolgaard.com/2009/05/30/mate-stopanddispatchhandlers-extension/

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

ActionScript 3.0, Adobe Flex

The "initCompleteHandler" function is protected in the FX4 DownloadProgressBar

Great news for all of us implementing Custom Preloaders…

Instead of having a private “initCompleteHandler” function on the DownloadProgressBar, the function is now protected so we can override it in custom implementations. This means that we no longer have to implement the IPreloaderDisplay interface and hack out a lot of the intended functionality in order to have the preloader also handling the load of the application logic so that it does not change to Application View until the Application is considered to actually be ready.

This is great news… making the DownloadProgressBar a lot better… now it all seems like just need some kind of “preventDefault” behavior in order to have total control over the switch from preloader to application without having to bloat the preloader itself…

Currently I am resorting to including either classes such as the PureMVC facade, a Mate eventmap or another kind of EventAggregator into the Preloader SWF in order to be able to hook into it… this is however only possible if you also hack a bit around in order to prevent the default switch from preloader to application.

ActionScript 3.0

Advanced ActionScript APIs… by Jacob Wright

While researching a question put forward by one of the Flex developers in Hello about Serialization/Deserialization to/from AIR databases, I stumbled across a video where Jacob Wright gets hands-on and concrete in giving ActionScript developers tips on how to create reusable libraries…
Including things such as using Proxy, IExternalizable, Code Namespaces and how to plan your new great API which will be easy to use for others and represent a lot of power…

Vodpod videos no longer available.
ActionScript 3.0

ActionScript 3 Enums

Based on my earlier writings about different ways of faking Enums in ActionScript 3, I decided to do my own based on Scott’s and Barney’s implementation.

Initially I have an Enum.as class from which my application-specific Enums will inherit from…

package com.hello.core
{
     import flash.errors.IllegalOperationError;
     import flash.utils.Dictionary;
     import flash.utils.describeType;
     import flash.utils.getQualifiedClassName;

     /**
     * An abstract class to emulate Enum type.
     */
     public class Enum
     {
          /**
          * To protect from instantiation after static initializing.
          */
          protected static var locks:Dictionary = new Dictionary();

          /**
          * Function to call for each enum type declared and in static init.
          */
          protected static function initEnumConstant(inType:Class):void
          {
               var className:String = getQualifiedClassName(inType);
               var typeXML:XML = describeType(inType);
               for each(var constant:XML in typeXML.constant)
               {
                    inType[constant.@name]._label = constant.@name;
               }
               locks[className] = true;
          }

          /**
          * Enum label.
          */
          private var _label:String;

          public function Enum()
          {
               var className:String = getQualifiedClassName(this);
               if(locks[className])
               {
                    throw new IllegalOperationError(”Cannot instantiate anymore: ” + className);
               }
          }

          public function get label():String
          {
               return _label;
          }
     }
}

As you can see, the implementation is a very crude combination of Scott’s and Barneys implementations.

An application-specific Enum could be something called ApplicationState.as, which might look something like this…

package com.hello.samples.skinning
{
     import com.hello.core.Enum;

     public class ApplicationState extends Enum
     {
          public static const FINAL:ApplicationState = new ApplicationState();
          public static const INITIAL:ApplicationState = new ApplicationState();

          // static ctor
          {
               initEnumConstants( ApplicationState );
          }
     }
}

Please forgive me for not including download links, but the classes are so simple that anyone interested should be able to copy-paste from here.

ActionScript 3.0

Reflection in ActionScript 3

To my great regret, it appears that Reflection is not going to be part of Adobe Flex 4 – Codename “Gumbo” since the thoughts of ES4 was dropped.

However, as an alternative it appears that the Maashaack framework is very much alive and have gained additional momentum on account of Microsoft obstructing ES4 (did I hear someone yell “prove it” ?)… however seeing that there are daily commits (the last seen on October 30th 2008) it might be worth to take a look at this framework for your ActionScript 3 works.

Check it out…
http://code.google.com/p/maashaack/

ActionScript 3.0

ActionScript Enums

I found myself almost posting an article about how to fake Enum’s in ActionScript, when Sam Rivello pointed me to an existing and very lightweight implementation by Scott Bilas.

http://scottbilas.com/2008/06/01/faking-enums-in-as3/

Browsing around a little bit more, I found a couple of more details relating to Scott’s implementation and things that could be added to the lightweight implementation by Scott.

One is Barney Boisvert’s addition of having the static constructor to prohibit the construction of instances other than the static constants instantiated at class loading time.

http://www.barneyb.com/barneyblog/2007/11/02/enums-and-actionscripts-static-initializers/

Both of these suggestions definitely beat the default implementations for Enums which involve using value types such as string and numeric values… so check it out if you are tired of using string literals in place of Enums.