Making FlexMonkey and Mate Property Injection Play Nice Together

For the past month I’ve had my head buried in the world of Flex programming. It’s an exciting world where rich interfaces can be easily prototyped and built out. Overall, I’m finding that the general enterprise development architecture for the platform is very young. And this can lead to some problems.

Two areas I’ve been focusing on are implementing a test strategy and framework for Flex applications, and implementing an MVC solution for flex applications.

For testing, I’ve been using FlexMonkey, which despite its youth, is a very handy application for testing stand-alone flex applications. It’s not so handy when it comes to testing an integrated application of traditional HTML based web-app which interacts with a Flex-driven application, but that’s an issue for another blog post.

I’ve also been using Mate for MVC implementation. But Mate is more than simply an MVC impl for Flex. It also provides IoC implementation, and a nice tag-based event handling and mapping architecture for interacting with the server.

For the past 24 hours I’ve been wrestling with an issue that emerged when our application was being tested inside of the FlexMonkeyLauncher.swf. We were encountering numerous ActionScript-style NPEs. Objects that were supposed to be bound and populated after a login event, were coming back null. But this was only happening when run inside of the FlexMonkey test runner. When our application was running standalone everything behaved fine.

Each of the bindable variables had one thing in common. They were being populated by Mate property injectors. Think of spring bean injection, but for Flex. When the application was run in FlexMonkey the property injection was silently failing. Eventually, I determined that because our app was not the parent app when FlexMonkey was involved, the Mate binder was not finding the target views in the run-time display list, and property injection was failing silently. It would be nicer if there was a debug log saying something like “Hey, that view you said had that one variable I should use? Remember that one? I can’t find it, so I’m exiting. Have a nice day!”

In the end, the solution was to use the InjectorRegistry singleton provided by Mate to explicitly register any views in my application which contained public variables which needed to be hooked up for bindable property injection. Here’s an example:

Here’s my Flex UIComponent instance, in this case a VBox.
Under normal circumstances it would have more attributes, but
I’m only calling out the necessary one for the example
<mx:VBox initialize=”onInit()” xmlns:mate=””&gt;

// Import the injector registry
import com.asfusion.mate.ioc.InjectorRegistry;

// Define the function to run when the component/view is initialized
private function onInit() : void {
InjectorRegistry.register(this); // Add this VBox to the injector registry


public var myBindableArray : ArrayCollection;


I tried a couple of other approaches, including the <InjectorTarget /> tag, but that didn’t work how I expected it to. I’d definitely be happy to hear from Mate or FlexMonkey folks who have a better workaround for this. But if you’ve run into this incompatibility, hopefully this solution will save you some time.

4 responses to “Making FlexMonkey and Mate Property Injection Play Nice Together

  1. Just passing by.Btw, your website have great content!

    Making Money $150 An Hour

  2. Thanks a lot! I have had exactly the same problem with the Mate/FlexMonkey combination and your workaround fixes the issue. You have saved my day ๐Ÿ™‚

  3. Hi, although maybe this is the only solution it is a really ugly one (no offense! i’ll explain later why…).

    Just a thought, did you try the localeventmap instead of the general one? It might help as in fact your app is now a subapp in the flexmonkey container.

    Anyway, One of the key features of Mate is that your view is independent of the framework, i.e. it contains no references to the framework. That loose coupling is gone now if you use your solution. Mate is about dependency injection and you just removed that ๐Ÿ˜‰ Also removing your view from the stage would probably keep it in memory (if InjectorRegistry.register(this) doesn’t use weak references). So you have to unregister it etc… This is not wat your want.

    I hope the local eventmap works out for you!
    Helped me once in a similar situation.

    All the best,


  4. I have the same problem, but only with the SWIZ framework. Has anyone found a solution to this problem?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google 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 )

Connecting to %s