ActionScript 3.0

A fun way to open a native window in AIR with MATE

Sometimes when coding it happens that you stumble on something which just strikes you as funny (sometimes for apparently no reason whatsoever).
One such experience happened today when I was coding an AIR client with MATE and I had to open a new NativeWindow.
It should be noted that I for this implementation am experimenting with ridding myself of using Managers (no other motivation than curiosity about will come out in terms of code design and architecture).

Well, the thing that amused me was to use a PropertySetter. This is due to the fact that you have to set the “visible” property in order to actually show the window. However, you also have to pass an object of the type “NativeWindowInitOptions” to the constructor.

The code eventually can be written like this…


<s>

	<s />

	
		
	

</s>



	

		
			
		

	



ActionScript 3.0, Adobe Flex

MATE CacheSetter.. a quick and dirty introduction

One of the newer classes in the MATE Flex Framework yet to be documented is the CacheSetter.
It’s nothing overly fancy, but it does exactly what it promises… it allows you to set the Cache from an ActionTag.

Let’s examine the code below… it’s a standard MATE EventMap with a couple of eventhandlers which offers to exit an AIR application when the User clicks anywhere on it… the applications for such a feature might be quite limited, but that’s what I could think of at 4:40 AM in Bangkok after almost 2 hours of being teleconferencing with the Flex Team sitting in California and it proves the point with the CacheSetter close to a minimal implementation.

NativeSystemEventMap.mxml




	
		
	

	

		
			
		

		
			
		

	


For the sake of completion, I will also bring the code to the AIR application itself…


<s>

	
		
	

</s>

One of the more interesting and intricate details (and eventually why this exercise is interesting), is to see that it uses the Class reference as the cacheKey and that you eventually would be able to use any class or hashable object and chain as the cacheKey. If the cacheKey is NOT set explicitly it will default to use the class type of the Generator attribute, but if you are working with MATE the Cache class is one of the classes it makes the most sense to take an extra look at…

CacheSetter (Source)
http://code.google.com/p/mate-framework/source/browse/trunk/src/com/asfusion/mate/actions/CacheSetter.as

Cache (Source)
http://code.google.com/p/mate-framework/source/browse/trunk/src/com/asfusion/mate/core/Cache.as

Cache (Documentation
http://mate.asfusion.com/api_docs/com/asfusion/mate/core/Cache.html

Uncategorized

REDO/ UNDO … How TODO

One of the most frequent requests I have pending in my Knowledge Pipeline is the question about how to implement REDO/UNDO… the classical approach seems to be the individual developer’s imagination, however it may prove to be the worst reference since it tends to diverge quite strongly in quality of implementation.

Check out the original Memeto pattern…. its quite cool in its implementation.
http://en.wikipedia.org/wiki/Memento_pattern


Uncategorized

Exception Shielding… let's do it

Use the Exception Shielding pattern to sanitize unsafe exceptions by replacing them with exceptions that are safe by design. Return only those exceptions to the client that have been sanitized or exceptions that are safe by design. Exceptions that are safe by design do not contain sensitive information in the exception message, and they do not contain a detailed stack trace, either of which might reveal sensitive information about the Web service’s inner workings.

For some anticipated exceptions that are safe by design, such as data validation errors, the Web service returns appropriate information to the client. For other exceptions, such as authentication failures, the exception logic sanitizes the exception, replacing it with an exception that is safe by design.

Remember, always create systems exposed to the internet based on some basic premises, such as e.g. not telling the caller of a service something revealing the implementation, but tell the caller something that only relates to the logical layer. Don’t do it for security alone, but allow the (developer) client of your service to gain enough information to go on a qualified bug-hunt…


Uncategorized

Quince… UX patterns library…

As I get older in this crazy business of attracting users and even going as far as attempting the daunting task of trying to make them happy and satisfied, I find myself examining HCI studies and other user centric disciplines…

Enter Quince…

Among one of the interesting ones getting a lot of attention these days are UxD patterns… first they got some love from Yahoo… and now anyone doing Web will have a UxD pattern library with at least 20% proprietary patterns (however, come to think of it, how can it be a SW pattern if its proprietary !?) … anyways…

If you find yourself working with real humans from time to time as end-users, don’t hesitate to check out Quince…

You can browse the library in a number of ways…
But I definitely recommend that you take it for a spin with Silverlight installed… it will definitely improve on the overall experience.

Infragistics are pretty cool…
http://quince.infragistics.com/


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.

Uncategorized

Introducing IANA

At the core of application development are protocols and standards… which without both we would all just be a bunch of hackers and cowboys.

I find myself browsing the IANA website often when I am defining an API – because as you will find out once you start using the IANA catalogue, there is a standard for everything and there is no need to break the standards if it can be avoided.

Some parts of the IANA catalogue are more useful than others… among the high-ranking sub-sites are the following…

MIME-types
http://www.iana.org/assignments/media-types/application/

Port-numbers
http://www.iana.org/assignments/port-numbers

…and among the more curious is the Operating-System-Names… which has not been updated for more than 6½ years…
http://www.iana.org/assignments/operating-system-names