Flex - Using the [Mixin] meta tag

A metatag that is rarely talked about in the Flex world is the [Mixin] tag.  This tags primary use is to create static code blocks to initialize parts of your application.  It is run when the SystemManager first becomes available.  So about as early in the the application startup process as you can get.  Access to the SystemManager at early stages of application startup can be invaluable.  Luckily, it is really easy to write a mixin. And is done in the following manner.

[Mixin]
public class MyMixinExample{

                 /**
		 * called due to the fact that i've used the [Mixin] metatag
		 * @param systemManager
		 *
		 */
		public static function init (systemManager:ISystemManager):void{
			//do stuff
		}

When the application starts up, if you have a [Mixin] tag at the beginning of the class, it looks for a static 'init' function, and passes the SystemManager as an argument to the function.  Very simple, infinitely useful.

If you have any questions or comments feel free to leave them below.

Tags: , ,

Leave a Reply