(This tag must be placed inside an <EventMap> tag)

An Injectors tag defined in the Event Map is a container for InjectorPropertys that will inject properties coming from a source to a target, but they can also be used for other purposes.

<Injectors target="{MyTargetClass}">

The Injectors tag are similar to the EventHandlers, and when executed, they will run all inner tags in order. EventHandlers are executed when an event of the matching type is dispatched. Injectors, on the other hand, are executed when an object of the class defined in the target attribute is created. In order for the Injectors to run, the object of that class needs to be created within the display list, or be instantiated by the ObjectBuilder or MethodInvoker tags.




The class that, when instantiated, should trigger the inner tags to run. This target must be supplied using bindings, but this binding is only executed once, when the event map is created.



If true, then subclasses of specified class will also trigger injection. If specified class is an interface, then classes implementing interface will trigger injection. If false, only instances of the specific class will trigger inner tags to run. Default is false.



Whether to show debugging information for this Injectors block. If  true, Console output will show debugging information as the injectors are applied.


Event handler

In the start attribute you can supply an event handler for the event of type ActionListEvent.START. This event is dispatched right before the actions (normally PropertyInjector items) are called, when the list starts execution.


<Injectors target="{MyTargetClass}" start="trace('Execution of injectors list started!')">


Event handler

In the end attribute you can supply an event handler for the event of type ActionListEvent.END. This event is dispatched right after all the items in the list have been executed.


<Injectors target="{MyTargetClass}" end="trace('Execution of injectors list ended!')">

Inner tags


PropertyInjector s defined in the Injectors tag will apply or bind properties specified in the source to the target specified in the parent Injectors target. See more information in the PropertyInjector documentation.


A ListenerInjector tag will add an event listener for a specific event type and call the specified method on the target specified in the parent Injectors target. See more information in the ListenerInjector documentation.

Other tags

All other tags allowed inside EventHandlers and MessageHandlers are allowed inside the Injectors. This allows you to inject other properties to the target, such as data coming from a server call (one-time only).

28 responses so far

  1. I'm really liking mate, but I'm not a big fan of the verbosity of using injectors. I guess compared to Cairngorm / j2ee it's not so bad, but the other half of my brain is ruby so you can see where I'm coming from.

    I understand needing an explicit getter and setter when you're doing more than just moving properties from the business logic to the view, but most of the time that's all I'm doing. Having to define code like this:

    [Bindable (event="heightChange")]
    public function get main_image_height():Number
    return _main_image_height;

    public function set main_image_height(h:Number):void
    _main_image_height = h;
    dispatchEvent( new Event('heightChange'))

    instead of just something like this:

    public [Bindable] main_image_height (need that event communication though...)

    is really painful.

    I need to dig in your code and see if I can contribute a solution to my problem, but I figured I would see if I'm just missing something here (I only started playing with Mate yesterday).

    Keep up the great work. Mate looks to be shaping up to be my framework of choice.
  2. Mike,
    setters and getter are the equivalent to a property. Nowhere here it says that you have to use getters and setters. The targetKey for PropertyInjectors needs just to be a public property, which doesn't even need to be bindable. How you expose that property (via a public property or via setters) is up to you.

    You can see an example of that here:

    I know this section of the docs is a little thin, so that is probably why you are missing that piece. I am working on writing more for this.
    If you have more questions, please refer to the forums.

  3. Do you have an example using START and END for its true purpose, thus not using trace() method.

    You documentation is difficult to understand. Do you mean



  4. You use a function as your event handler for start or end events:
    start="yourFunction()" or start="yourFunction(event)" or start="yourFunction('some value')"
  5. Laura, Can you pls elaborate on what you mean when you wrote "Injectors, on the other hand, are *executed* when an object of the class defined in the target attribute is created."? I don't understand that because I think of injectors and their inner tags also as (as3) objects, which are instantiated and initialized (just after the parent eventmap object is instantiated) and then injectors have some properties and some methods which may be called. To try understand what you mean, I looked at the FB3 generated as3 source.
  6. Emmett,
    It is true that the whole event map is defined once, all the objects are created in the beginning and that's it. But those objects are registered to listen to events. If you take the example of the EventHandlers, each EventHandlers in the EventMap gets created in the beginning, but when an event is dispatched that matches the type attribute, those EventHandlers "run", in the sense that they "execute" the steps defined by their inner tags (which also were only defined once). So in this sense, EventHandlers and Injectors contain a recipe with steps that they will "execute" any time needed. For the EventHandlers, that time is when an event is dispatched, for the Injectors is when an object is created (an object that matches the class specified in the target). Does that clarifies it?
  7. Laura, Thank you. That does explain a couple of things. Firstly it was never obvious to me that Injector tags (objects) listen for events. For Eventhandlers this always was assumed (good naming of course). For injectors I think I understand now. You also made me realize why Injectors are defined in the EventMap. Secondly it would seem that unlike typical EventHandlers, Injectors might be executed very rarely or even just once. eg. Look at the StockQuoteExample app. If I understand Flex right, then only one single QuotePanel injection target object is defined, so the single app Injector is I assume executed just once when the view is assembled. To me it looks like that Injector simply sets itself up as some kind of data binding middle point, and then after that, its "execution" job is done forever! Right??
  8. That's right.
  9. Hi Laura, thanks for clarifying this point for us. To exploit injection properly/fully, I believe it's essential this "event time of binding" concept is understood correctly.
  10. Laura, you said that : "for the Injectors is when an object is created (an object that matches the class specified in the target)"
    i'm currently working on a project with three views.
    on the first view, you have a list of person,
    when you select a person (person1), a view pop and show informations.
    if you select another person (person2), you'll get a new view with the second person informations. the two views (person1 & person2) are display at the same time on the screen.
    at this moment, all is ok,
    so, let's complicate it : the information view is a viewStack, with two views : viewA and viewB, on viewB, i have a list.
    how can i populate the list in viewB on person1 without making change to the list in viewB on person2 ? is it possible with Injectors ?
  11. Setters, via injectors(of Strings, int, Number), seem to work consistently. However, when using Object (ArrayCollection), setters may not always work as expected.
  12. Is there a way to get a reference back to the object that the injector is dealing with from inside the tag block? Say, for example, whenever an instance of ClassA is created an ObjectBuilder runs, creates an instance of ClassB, and passes a reference of ObjA to ObjB. Many thanks!
  13. event.injectorTarget seemed to do the trick :)
  14. {MyTargetClass} is instantiated and cached when it is first created, but is there a way to remove it from the cached when it being destroyed or no longer being referenced in the application?
  15. I have the same problem that @loop. What is the solution for multiple instances of the same view ??

Leave a response

If you need help or want to comment on something not related to this page, please post in the forums. Thanks!

Leave this field empty