(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

  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:<br />start=&quot;yourFunction()&quot; or start=&quot;yourFunction(event)&quot; or start=&quot;yourFunction('some value')&quot;
  5. Laura, Can you pls elaborate on what you mean when you wrote &quot;Injectors, on the other hand, are *executed* when an object of the class defined in the target attribute is created.&quot;? 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,<br />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 <a href="EventHandlers</a>">">EventHandlers</a>;, each <a href="EventHandlers</a>">">EventHandlers</a>; in the <a href="EventMap</a>">">EventMap</a>; gets created in the beginning, but when an event is dispatched that matches the type attribute, those <a href="EventHandlers</a>">">EventHandlers</a>; &quot;run&quot;, in the sense that they &quot;execute&quot; the steps defined by their inner tags (which also were only defined once). So in this sense, <a href="EventHandlers</a>">">EventHandlers</a>; and Injectors contain a recipe with steps that they will &quot;execute&quot; any time needed. For the <a href="EventHandlers</a>">">EventHandlers</a>;, 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 &quot;execution&quot; 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 &quot;event time of binding&quot; concept is understood correctly.
  10. Laura, you said that : &quot;for the Injectors is when an object is created (an object that matches the class specified in the target)&quot;<br />i'm currently working on a project with three views.<br />on the first view, you have a list of person,<br />when you select a person (person1), a view pop and show informations.<br />if you select another person (person2), you'll get a new view with the second person informations. the two views (person1 &amp; person2) are display at the same time on the screen.<br />at this moment, all is ok,<br />so, let's complicate it : the information view is a viewStack, with two views : viewA and viewB, on viewB, i have a list.<br />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. 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 <a href="ObjectBuilder</a>">">ObjectBuilder</a>; runs, creates an instance of ClassB, and passes a reference of ObjA to ObjB. Many thanks!
  12. event.injectorTarget seemed to do the trick :)
  13. {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?
  14. I have the same problem that @loop. What is the solution for multiple instances of the same view ??
  15. I've posted this within the propertyInjector forum as well but it is related to this too ...<br /><br />&lt;Injectors target=&quot;{MyTargetClass}&quot;&gt;<br /><br />You reference the Class and not an instance of the class. What if I'm using multiple instances and need to inject into a specific one?
  16. You can use targetId in your inner tags to distinguish instances.
  17. Hi Mate Team!<br /><br />I just started using Mate and I think it's great! <br /><br />I have a question and would appreciate it if you could shed some light on the matter.<br /><br />The last sentence of the second paragraph reads:<br /><br />&quot;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 <a href="ObjectBuilder</a>">">ObjectBuilder</a>; tag with attribute registerTarget=&quot;true&quot;.&quot;<br /><br />However, the registerTarget property doesn't seem to be documented in <a href="ObjectBuilder</a>">">ObjectBuilder</a>; page. Am I missing something?<br /><br />I also come across another probable discrepancy. In the <a href="MethodInvoker</a>">">MethodInvoker</a>; page <a rel="nofollow" href=""></a>;, it is explained that the cache attribute can take either of the values &quot;global&quot;, &quot;inherit&quot;, &quot;local&quot; or &quot;none&quot;. But an example, a few paragraphs down, suggests that the cache attribute is of Boolean type:<br /><br />&lt;<a href="MethodInvoker</a>">">MethodInvoker</a>; generator=&quot;{MyWorker}&quot; method=&quot;doWork&quot; cache=&quot;false&quot; /&gt;<br /><br />Could you please shed some light on this one too?<br /><br />Cheers,<br /><br />Naso.
  18. Can there be only one injector in an event map or we can have multiple injectors?
  19. You can have as many Injectors as you want.
  20. I'd like to inject all classes in a class hierarchy. E.g., if I have:<br /><br />class FooBase<br /><br />and<br />class FooSub1 extends FooBase<br />class FooSub2 extends FooBase<br /><br />...I want to inject any instances of FooBase, FooSub1, and FooSub2 using a single Injectors block.<br /><br />Is it possible to do this without explicitly listing every subclass in the 'targets' attribute of the Injectors? Simply listing FooBase doesn't seem to do the trick.<br /><br />(The end user can create custom subclasses of FooBase, and it's a bit inconvenient to update the Injectors definition with these custom classes.)<br /><br />Cheers,<br />Aron
  21. Aron,<br />You can set the target to be the super class, and use the includeDerivatives attributes as true and then subclasses will also be injected.
  22. Brilliant! Thanks for the quick response.<br /><br />Cheers,<br />Aron
  23. Hi!<br /><br />I have question about parameter target.<br /><br />My code MyEventMap<br />&lt;Injectors target=&quot;{MyView}&quot;&gt;<br /> &lt;PropertyInjector targetKey=&quot;model&quot; source=&quot;{MyViewModel}&quot;/&gt;<br />&lt;/Injectors&gt;<br /><br />When instance of class MyViewModel is injecting in property model of MyView?<br />1. Only when MyEventMap is created. And if at this moment i don't create yet MyView - injecting don't work.<br />2. When MyView is added to display list?
  24. I think i found bug - if added view in ViewStack in Flex 4 app after creating <a href="EventMap</a>">">EventMap</a>;. Injector is not work.<br /><br />May be event of creation view in some reasons don't dispatch
  25. I am new to Mate and have been using Flex with ColdFusion for about a year. I am having a bit of trouble understanding how to get information back to the view correctly. For example, I want to store a users session in a object (user_id,first_name,last_name, etc) so I can access these class properties from my views. <br /><br />I think I understand how to populate the class properties correctly, but I'm not sure how to pull them into my views for later use. I have researched Injectors/Setters/Getters and I'm not sure which is the correct way to handle this sort of information.<br /><br />Any advice or examples from anyone would be much appreciated!<br /><br />Thanks to everyone and the asFusion team for sharing their knowledge!
  26. First, i'm new with Flex and Mate and i found it great.<br /><br />Is it possible, with injectors, to applicate a skin on each Button that are instantiate.. ? Here I say Button, but it could be any other component.<br /><br />I would like that because i have a lot of component with skins and it would be great.<br /><br />Thank for the answer
  27. if have a component called filter. and when i press it to send data to my result view or data to my search view. <br /><br />It depends on wich view i put my component. <br />the problem is if inject the data will go to my 2 views <br /><br />any solution ? ^^
  28. I have a view that i want to dynamically add a child UIComponent element after an event i have handled in the eventhandler.<br />With the injector how do i do this if i don't have access to the view.<br /><br />model doesn't know about the view? so can't add a component, it can use dependency injection to know about the change in data in the view but can't add an element to itself or can it?

Comments now closed