Sample application using the Swiz Framework and BlazeDS

There have been a lot of discussions around Flex Frameworks lately. Tony Hillerson has an interesting series here: 1 2 3 4 5 6

A relative newcomer on the list is Swiz, the work of Chris Scott. I figured I would give it a try, and create a Swiz version of the inSync application that I often use to try out and demonstrate different features and techniques in Flex and Adobe AIR. This is not an endorsement of Swiz over other frameworks. I simply wanted to share the sample application I built as part of my own research as a (neutral like a Swiss) Evangelist.

View the source code.

Application Highlights:

At his core, Swiz is a simple inversion of control framework. Using an IoC framework, the components of your application (for example, Views) don’t instantiate or even look up their dependencies (the objects they work with). The framework injects those dependencies when the components are created (hence the term “Dependency Injection” also used to describe this approach). The result is looser coupling and more reusable components. The components managed by the Swiz IoC framework are called beans.

1. Defining your beans

The beans of the inSync applications are defined in Beans.mxml:

<BeanLoader xmlns="org.swizframework.util.*" xmlns:mx="" xmlns:controllers="insync.controllers.*">

    <DynamicChannelSet id="myAmfChannel">

    <mx:RemoteObject id="contactService" destination="contacts" channelSet="{myAmfChannel}"/>

    <controllers:ContactController id="contactController"/>


2. Bootstrapping Swiz

You bootstrap Swiz in the preinitialize event of the application. You can have multiple Beans configuration classes. You pass your configuration classes in an array as an argument of the loadBeans function. In inSync, we have only one configuration class (Beans.mxml).

Swiz.loadBeans( [Beans] );

3. Injecting dependencies

Swiz uses the [Autowire] custom metadata to inject beans into other beans and views.
In inSync, the contactService RemoteObject is injected into as follows:

public var contactService:RemoteObject;

… and contactController is injected in the Views. For example, in ContactForm.mxml:

public var controller:IContactController;

Because we use an interface, the View is not coupled to a specific implementation of the controller. If you don’t like to have a reference to the controller in your view, keep reading…

4. Dynamic Mediators

Swiz is an IoC framework. Beyond that, it doesn’t force you to use any specific design pattern. So, if you don’t like to have a controller in your view, you can, for example, set up the view to dispatch events instead. For example, in the save() function of ContactForm.mxml, you would replace:;


Swiz.dispatchEvent(ContactEvent.SAVE, contact);

You could then listen to this event in some “mediator” class using Swiz.addEventListener(ContactEvent.UPDATE, someHandler), but the dynamic mediator feature of Swiz allows you to automate this process. For example, you could annotate the save() function of the ContactController class as follows:

[Mediate(event="ContactEvent.SAVE", properties="contact")]
public function save(contact:Contact):void
	executeServiceCall(, save_result, null, [contact]);

Swiz will automatically set up an event listener, invoke the annotated method when the event is dispatched, and pass the specified event properties (in this case: “contact”) as the function parameters.

5. Prototypes

By default, components defined in your Beans configuration classes are singletons. In other words, the same instance of a Bean gets injected everytime it is autowired. In some situations, you may want to inject a new instance of a Bean everytime it is autowired. For example, if you open multiple instances of the same View, you may decide you need one controller per view. Prototypes allow you to define non-singleton Beans in your Beans configuration class using the following syntax:

More on prototypes here.

<factory:Prototype xmlns:factory="org.swizframework.factory.*"

Installation instructions:

  1. Install the BlazeDS turnkey server. (To be clear: you don’t have to use BlazeDS to use Swiz… That’s just the sample I wanted to build.)
  2. Download, and unzip it on your local file system.
  3. Copy insync-swiz/java/classes/insync to blazeds/tomcat/webapps/samples/WEB-INF/classes/insync.
  4. Add the following destination to blazeds/tomcat/webapps/samples/WEB-INF/flex/remoting-config.xml:
  5. <destination id="contacts">

  6. Copy insync-swiz/sampledb/insync to blazeds/sampledb/insync
  7. Edit in blazeds/sampledb, and modify the file as follows to add the insync database to the startup procedure.


  8. Start the database (startdb.bat or
  9. Start BlazeDS
  10. In Flex Builder, create a new Flex project called insync-swiz. You don’t have to select any “Application server type”.
  11. Copy the Swiz swc and the flexlib swc (used for the SuperTabNavigator) from insync-swiz/flex/lib to the lib directory of your project
  12. Copy the files and folders from insync-swiz/flex/src to the src directory of your project
  13. Open Beans.mxml and make sure the serverPort and contextRoot properties in DynamicChannelSet match your server setup.
  14. Run the application


Swiz was easy and enjoyable to work with. It is also non intrusive and definitely introduces some interesting ideas. A few lingering questions I didn’t have time to investigate…

  • Swiz relies on introspection (describeType) to find its custom metadata in the objects added to the display list (with the exception of classes in the flash.* and mx.* packages). This has a performance impact. I’m not exactly sure how much of an impact it would have in real life apps yet…
  • How well does Swiz work with Modules or Marshall Plan subapplications?

If you are looking for more information, check out the following resources:

  • Hi Christophe,
    cool article and nice explanation of Swiz!
    One thing I would like to comment is:
    public var controller:IContactController;

    You could leave out the bean name if there exists only one instance in your beans of that type aka autowire-by-type and it would read:
    public var controller:IContactController;

    And thanks for the link!
    Brian Kotek also did a blog series about Swiz which is pretty cool:

  • Nice Framework!!!!! Very Very intersting!! since Spring uses IoC right?


  • Pingback: Shared Items - March 1, 2009 |

  • Pingback: Christophe Coenraets » Blog Archive » The “Spring ActionScript” Framework – Part 2: Autowiring()

  • Pingback: Christophe Coenraets » Blog Archive » Building a Flex Application with the Parsley Framework()

  • Lawrence

    I have tried Swiz but so far have issues and after a day, not sure I’ll continue but I love the concept. Can anyone explain why my service would always be null when loaded in Beans.mxml?

    I use Grails on server side and when I have in my mxml file the same RemoteObject definition I can access the service properly and it is not null like it is when using Swiz.

    Any help appreciated.

  • Lawrence

    Somehow this didn’t make it into my post….this is my service in either Swiz Beans.mxml or in my main app mxml.

  • Lawrence
  • Lawrence

    Ok, I give up :) – my code is never included in a comment here!

  • Ansury

    Lawrence, I can’t see your example but clearly you’re missing something. :) Follow the instructions on the Swiz framework distribution page, if you do everything there it will work. After working with it a few more days it should become pretty obvious what to check for.

  • Pranay

    I used Parsley ( )framework in my last project. Its very light weight, easy configurations, annotations, complete seperations of reusable components.
    I liked that.

  • Amit

    Your articles are always nice and developer friendly :)
    We are going start a project in which we will be using Flex+BlazeDS+Spring. We are using Spring BlazeDS integration for the same.

    But some how our team does not like the tight coupling of calling spring pojo method from Flex UI.
    Can we use any controller in between?
    Or can you suggest us an alternative to avoid this Tight coupling?

  • Pingback: [Flex & AIR] Swiz Framework – meus primeiros passos | Erko Bridee()

  • en deli porno videolari tikla hemen izlemeye basla.

  • Pingback: Felipe Borella » Swiz Framework()

  • The Adobe AIR runtime permits developers use the Flex framework to build rich web applications that run as standalone client applications without the constraints of the browser. Adobe AIR applications run across desktop operating systems and on Android, BlackBerry® Tablet OS, and iOS mobile operating systems. With AIR, Flex developers can use their existing skills and code to build highly engaging, visually rich applications that merge the power of local resources and knowledge with the reach of the net.

  • Please find attached my presentation about Swiz from yesterday. As I already said, I am liking Swiz and I will definitively use it in my projects where I think its appropriate. Not only because I am Swiss ;) , but also because it addresses the main things I miss in Flex like IoC, sometimes dont like in PureMVC like boilerplate code or built over and over again like the dynamic channels.

  • Pingback: Mxml samples | Eyesoftheeast()

  • I really enjoy looking at about this site, it contains superb posts.

  • Hi i am kavin, its my first occasion to commenting anyplace, when i read this piece of writing i thought i could also make comment due to this good paragraph.

  • Asking questions are really pleasant thing if you are not understanding anything completely, however this
    article gives nice understanding even.

  • Wow, incredible blog layout! How long have you been blogging for?
    you made blogging look easy. The overall look of your site is magnificent,
    as well as the content!

  • Hi there! This post couldn

  • ali khan

    Always research before you buy any SEO application because search engines Algorithms are never stand still thereby improving their look for technological innovation to provide the most appropriate results for their customers. SEO tools for Google, MSN and Google are numerous. official sites

  • ali khan

    Provided that the author benefits people with creativeness, design and/or enough information; expecting to business those, as it were, in come returning for the visitor’s toleration of a little repetition; there may still be appropriate interaction going on. Be it ever SEO little or ever SEO unexplained. check out

  • ali khan

    SEO Company.SEO-India provides a variety of web growth and check engine optimization help, efficiently, on efforts and within budget. We are your single source connection to freelancing from Indian, web style web solutions of the finest top quality. Today, there is lots of competition in IT, and your web page can not be efficient in gaining the target viewers and the preferred results if only a simple HTML program, and it should be amazing, developing technological innovation, and it looks in existence. see post

  • ali khan

    Regional SEO establishes a robust on the internet existence for your organization exactly where the people who are most likely to buy from you will see you – on the first page of google look for motor outcomes. Any local SEO technique determines relevant, timely, high-demand keywords and keyphrases that clients use to discover the services or goods that your company provides. Tikato Shop


      This is the objective why clients from all over Local indian native are nowadays gathering at their gateways for the projects being done. go to website

  • ali khan

    Bad connecting can be intensely punished by Look for search engines Penguin and create the web page suffer for extremely extended times. reference link

  • ali khan

    There are bundles of other SEO techniques that might be used to help you obtain your goals, so create certain that you be a part of with a genuine company to help you out in your web marketing. trivia crack

  • ali khan

    Opinions for the execute done by a seo organization in Delhi is changing the most adverse clients into beneficial ones. find here

  • The 2009 edition of the Tour of California starts tomorrow.

  • julian julian

    Compro Oro Parma, quotazioni borsistiche aggiornate in tempo reale. Blocca il prezzo dell’Oro o del’ Argento e vendi in tempo reale alle migliori quotazioni.

  • TargbaBenjamin