Announcement Announcement Module
No announcement yet.
Externalizing ChannelSet Config WIth Spring Actionscript Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Externalizing ChannelSet Config WIth Spring Actionscript

    Here are a few tips gained from how I managed to externalize ChannelSet configuration in a Flex Client using Spring Actionscript (SAS).

    1) I'm pretty new at this, but what I've done works
    2) Parsley or Swiz or whatever other framework may be better but I used SAS because it leverages what little I know about Spring Framework for Java.
    3) These are just notes on things that caught me - you need to read the SAS documentation carefully, it is very clear and precise, but some important details are easy to miss if you go too quickly


    I have an Flex client and want it to talk to one server during test and another after deployment. In fact there are several deployments of the same application differing exclusively by which server they talk to.

    The examples of Flex-Blaze integration I see out there tend to have the channel set hard-coded in the client and clearly this will not work for me (or you?). The examples often acknowledge that hard-coding is bad practice and say "use a framework like Spring Actionscript, Swiz or Parsley". So I did. Here's what I learned:

    1) download SAS *with dependencies* (Obvious, right? Wasn't to me.)

    2) Make sure you add both the SAS "dist" and "lib" directories to your Flex Builder Path. (Aside: there's other cool stuff in the as3-commons libraries - I like their Assert class for example.)

    3) Set the Flex Compiler Option -keep-as3-metadata += Autowired. You want Autowired because it will let you grab stuff from the SAS context whenever you need it. Like, for example, any place you want to create a service and configure it with a channelSet from the context.

    4) write your context configuration XML file as per the documentation. In mine I configure a channelSet as follows when working against a local server - and then simply change it when I deploy.
        <object id="channelSet" class="mx.messaging.ChannelSet">
            <method-invocation name="addChannel">
                    <object id="amfChannel" class="mx.messaging.channels.AMFChannel">
                        <property name="url"
                            value="http://localhost:8080/MutantManager/messagebroker/amf" />
    5) To make autowiring work, you must also include this in your SAS context config file:

    <object id="autowiringStageProcessor"  class="org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor" />
    6) Oh yes, but of course nowhere in your code does anyone include that lovely DefaultAutowiringStageProcessor so of course you get a runtime error when you first try to run it. You solve that little obstacle in one of the 6 ways described in the last section of the SAS documentation. Cutting to the chase, I do the following in my Application:

                import org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor;
                // just to get the class loaded - it's a Spring Actionscript thing
                public var _dummy:DefaultAutowiringStageProcessor;
    7) also in your main code you need to deal with a bit of timing so that the SAS context is loaded up before you start doing the heavy lifting. Here's what I wrote: (In case it is not obvious, MainView holds my client application, and I named my config file client-config.xml which is not the default.)

                // this is the Spring ActionScript Container wich holds 
                // externally configured objects and dependencies.
                public var sasContext:FlexXMLApplicationContext;
                protected function applicationCompleteHandler(event:FlexEvent):void
                    sasContext = new FlexXMLApplicationContext();
                    sasContext.addEventListener(Event.COMPLETE, sasContextLoaded_handler);
                // Timing note: for autowiring, we need to ensure that the 
                // Spring Actionscript context is loaded before we add anything to the stage.
                public function sasContextLoaded_handler(e:Event):void {
                    var mainView:MainView = new MainView();
    8) Within the staged objects, you can now pull the channelSet out of the SAS context to configure services anywhere in your want with this little bit of code:

                public var channelSet:ChannelSet;

    I suppose that there are a million other ways to have accomplished this, but I hope this helps someone. But please, read SAS documentation.

    If you are critical of this approach - I am more than happy to learn why.

    Ted Moens

  • #2
    This question comes up all the time, so I'm sure this example will be very helpful, thanks!