This post is not about using Mixin metadata tag. There are tons of documentation on the web to explain about usage. Here are a couple of useful links:
http://adamflater.blogspot.com/2007/03/static-code-blocks.html
http://www.adobe.com/support/documentation/en/flex/1/mixin/
In fact, this post is about to warn you about some of the examples. In short, when you use Mixin, Flex will make sure that “init” method will get call on your class when SystemManager is ready or your Module is initialized.
Here is typical signature we found on most of the examples:
public static function init(systemManager:ISystemManager):void
This works great as long as your class is not referenced from Flex module. Why? I am glad you ask. The process of calling “init” can happen from two places. One is SystemManager if your class is referenced from main application and the other one is FlexModuleFactory if your class is referenced inside a flex module. When “init” is called, either SystemManager or FlexModuleFactory passes itself as argument to the function and FlexModuleFactory never implemented ISystemManager. So, it failed. But you will never see error message because there is do-nothing-try-catch block around that call.
Lesson learned is one should use interface or parent class of both SystemManager & FlexModuleFactory, there are a few of choices for you, for example, IFlexModuleFactory, DisplayObject, Sprite and etc. For me, I stick with “Sprite” though there a few example from Adobe using “DisplayObject”.
[Mixin]
public class MixInTestDelegate {
public static function init(root:Sprite):void {
trace("I will get called in main application and module");
}
}
Post a Comment