Announcement Announcement Module
Collapse
No announcement yet.
having trouble getting Autowired to work with stage components in 0.8 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      Found the problem. Was using XMLApplicationContext instead of FlexXMLApplicationContext.

      Thanks for the tip with the self dispatching events.

      Comment


      • #4
        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

        Comment


        • #5
          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.

          Comment


          • #6
            ?

            That is very weird, even after a clean build?

            Comment


            • #7
              Originally posted by 666shooter View Post
              That is very weird, even after a clean build?
              Yea, just tried it again, and it's autowiring.

              Comment


              • #8
                I've experienced the same thing. I'm building on 4.0.0.7219, so maybe they've changed the compiler to automagically include all metadata by default. Check out your {FLEX_HOME}/frameworks/flex-config.xml file. If you see the <keep-as3-metadata> tag commented out, you're seeing what I'm seeing.

                Even though it's commented out, everything is working fine. It's pretty weird

                Comment

                Working...
                X