Results 1 to 8 of 8

Thread: having trouble getting Autowired to work with stage components in 0.8

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Posts
    7

    Question having trouble getting Autowired to work with stage components in 0.8

    Need some help getting Autowired to work. I am fairly new to Flex, been playing with it for a couple of months and now starting a new project and would like to use Spring DI for it.

    I have custom mxml component that extends form and I am trying to inject a CairngormEventDispatcher into the component. So what I have in the form is:


    [Autowired(mode='byType')]
    public var cairngormDispatcher:CairngormEventDispatcher;


    In my app context I have:


    <object
    id="cairngormDispatcher"
    class="com.adobe.cairngorm.control.CairngormEventD ispatcher"
    factory-method="getInstance"/>

    I have my project setup in flexmojos and eclipse builder, in flexmojos I've added:

    <configuration>
    <keepAs3Metadatas>
    <keepAs3Metadata>Autowired</keepAs3Metadata>
    <keepAs3Metadata>Bindable</keepAs3Metadata>
    <keepAs3Metadata>Events</keepAs3Metadata>
    </keepAs3Metadatas>
    </configuration>

    which results in: -compiler.keep-as3-metadata Autowired Bindable Events
    in the compile output of flexmojos.

    And in Eclipse builder I've also added: -keep-as3-metadata "Autowired"

    I've tried building the application both ways and neither one does the Autowiring.

    I know the app context is loaded correctly, I can do a getObject with "cairngormDispatcher" and it works. I am loading the app context on the applicationComplete event, but also have tried it with creationComplete and preinitialize.

    Also I did a new FlexStageDefaultObjectSelector().approve on the custom component to verify that it would be considered for Autowiring.

    So what could be wrong here? Is the compiler somehow just not picking up the
    Autowired metadata? How can I investigate this further? Thanks in advance for any tips.

  2. #2
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default weird

    first of all I'd suggest in Eclipse to change your compiler argument to -keep-as3-metadata += Autowired, otherwise the other metadata's will be removed.
    So far I can't really say what you're doing wrong, everything looks in order. Is it possible for you to post a small flex project here in which you only add this functionality?
    Perhaps judging from that I can figure out where things go wrong.

    Oh, and on a sidenote, you don't really need to inject the CairngormEventDispatcher, if you use the latest version of Cairngorm (I think its 2.2.1 or something) the CairngormEvents are 'self-dispatching'.

    So instead of writing this:
    Code:
    CairngormEventDispatcher.getInstance().dispatchEvent(new MyCairngormEvent());
    you write this:
    Code:
    new MyCairngormEvent().dispatch();
    That saves some typing

    cheers,

    Roland

  3. #3
    Join Date
    Aug 2006
    Posts
    7

    Default

    Found the problem. Was using XMLApplicationContext instead of FlexXMLApplicationContext.

    Thanks for the tip with the self dispatching events.

  4. #4
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default cool

    Hey there,

    good to hear things worked themselves out for you If you run into anything else, feel free to ask away.

    cheers,

    Roland

  5. #5
    Join Date
    Aug 2006
    Posts
    7

    Default

    The interesting thing now is that I don't need "-keep-as3-metadata" in eclipse or in flexmojos anymore autowiring with the metadata just works.

  6. #6
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default ?

    That is very weird, even after a clean build?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •