Need Help?

For technical questions, feel free to ask on the Swiz mailing list.

Save as HTML or PDF

You can export this entire Wiki in HTML or PDF format.

Skip to end of metadata
Go to start of metadata

Page Contents:

You can download this Quick Start as a Flash Builder FXP or Zip file. It's also available in the Swiz Examples repository on GitHub, along with more examples.

A Lightning Look at Configuration

Configuring Swiz in your Flex or AIR application is very straightforward: declare Swiz, define the beanProviders and config properties, and optionally define one or more loggingTargets to view debugging messages. Here is an example:

Non-visual components that you want Swiz to manage are defined in a BeanProvider tag. Any beans that you define within the BeanProvider are processed by Swiz for dependency injection and the creation of event handlers. In the following example, a UserService and a UserController are created:

The "Big Three": Dependency Injection, Event Handling, and Server Interaction

The three most commonly used features of Swiz are its dependency injection capabilities, its event handling features, and its server interaction utilities. Let's look at how each of these work.

Adding Dependency Injection

Dependencies are injected by using [Inject] metadata. In this example, the UserService is injected into the UserController:

In addition to injecting a bean, you can inject individual bean properties. In this example, the currentUser property of the UserController is injected into a UserForm visual component. Note that it is not necessary for the UserForm to be declared as a bean in the BeanProviders tag. When visual components are added to the display list, Swiz automatically inspects them and processes any metadata tags that are found.

Dispatching and Handling Events

When using Swiz, you dispatch standard Flex events. In this example, we've expanded the UserForm to create and dispatch an event when the form button is clicked. Swiz listens for events being dispatched within the display list and handles them automatically.

A look at the UserEvent confirms that this is just a simple, standard event. The only thing to note here is that the event has bubbles set to true. This allows the event to bubble up the display list so that it can be handled by Swiz:

We've seen how to dispatch events from the display list, but how do we handle the events? Swiz provides a [EventHandler] metadata tag to do this. In the example below, we have expanded the UserController to add an event handler method. In this case, when Swiz encounters an event of type UserEvent.SAVE_USER_REQUESTED, it will automatically invoke the saveUser method in the UserController. By specifying a value of "user" for the properties attribute, Swiz will locate the user property in the UserEvent and pass this as a parameter to the handler method:

One last feature to note regarding event dispatching. We've seen how an event dispatched from the display list will bubble up until it is processed by Swiz. But what about dispatching events from non-visual components like controllers and services? Swiz offers the [Dispatcher] metadata tag to meet this need. In the UserService shown below, Swiz will automatically inject an event dispatcher into the dispatcher property. Any events dispatched though this dispatcher will also be processed by Swiz and trigger any event handler methods associated with the event:

Talking to the Server

Our UserController can now respond when a save user event is dispatched. The final piece of the puzzle is having the application make a call to the server to actually save the user in a database. Typically, Flex requries you to manually create Responder objects to attach to AsyncTokens that will handle ResultEvent and FaultEvent. Swiz offers some helpful features to sidestep these manual processes. Below, you see the final version of our UserController. Because it has the Swiz helper object ServiceHelper injected, we can use its executeServiceCall() method. This method will automatically obtain the AsyncToken for the RPC call and create Responder objects. In this case, we call userService.saveUser(), and specify handleSaveUserResult to handle the successful response from the server. Although it is not shown here, we can also specify a method to use as the fault handler.

There's More Where That Came From

This quick tour has shown how easy it is to configure Swiz and use its core features. But Swiz offers much more than this! Please read the User Guide, Best Practices, and Advanced Topics to learn more.

  • No labels


  1. Anonymous

    produces a compiler error, because an array is expected.

    Wrapping the tt in an array produces a RTE (sorry in german):

    1. Hi,

      That error is actually saying that any tag (Class) defined in the loggingTargets tag must be a subclass (Type) of AbstractSwizLoggingTarget.

      I'm new to the framework but, I assume this is something that has changed in the rc release.


    2. Anonymous

      You removed the lines mentioned, but still refer to them in the text above the example.
      This works for me as long as there is no default implementation for the AbstractSwizLoggingTarget

      with a

  2. Anonymous

    What happened to the documentation for Swiz 0.6.4?  Not everyone wants to upgrade immediately and the old documentation is still needed.

  3. Anonymous

    Plus 1 for adding in the Swiz 0.6.4 docs.  Also a compiled .swc would be nice if we just want the library and don't want to build ourselves.  I know it is easy, but saves a step if I just want to run through a quick test.  Also, examples seem more geared toward flex4 than flex3 (which used to be there on the old site).  Having a 'legacy' section would be nice, the docs exist already.

    1. Anonymous

      Please indicate the url for the docs to Swiz 0.6.4.  I must be going blind and don't see it.

  4. Anonymous

    Please provide

    )printer friendly version of page

    )direct link to *.fxp

  5. Anonymous

    Is there a zip or fxp with this quick start in it?

    I'm attempting to get this quick start code running in FB4 ... and it doesn't.  It does compile with a few modifications (I added a class and added a few namespace declarations to Beans.mxml)

    Fails out with the error:

    Error: InjectProcessor Error: bean of type [class ServiceHelper] not found! at org.swizframework.processors::InjectProcessor/addInjectByType()[/Users/asstrochris/Documents/my_projects/swizframework-git/swiz-framework/src/org/swizframework/processors/]

    [... rest of stack trace deleted ]

    1. Since there are several examples at Github, I didn't think zipping up this code would matter much. But since a few people have asked for it, I will put one together. Thanks.

    2. Added the FXP and ZIP!

      1. Anonymous

        Hi, I downloaded the example and updated the swiz.swc file to swiz-framework-v1.0.0-RC2.swc (latest build file). However it is not working with the code. I tried to create one sample example and it dose not work with swiz-framework-v1.0.0-RC2.swc. Can you please let me know if I am doing anything wrong.


        1. It should work with the swiz.swc included with the example.

          1. Anonymous

            Thanks  Brian for your quick reply. It is working with swiz.swc. Is the swiz.swc file RC2 version? And why the swiz-framework-v1.0.0-RC2.swc dose not work? Should


            1. Anonymous

              I had the same issue. I think the guys changed [Mediate] to [EventHandler] since RC2. This is reflected in the bundled swiz.swc.

              1. Anonymous

                It's backwards.  RC2 changed [EventHandler] to [Mediate]. Therefore, in file "" on line 30, change [EventHandler(...)] to [Mediate(...)] if you are trying to get RC2 to work.

                1. EventHandler was added after RC2. So if you're using RC2, use Mediate. As I said, the swc included with the code should work without any changes.

  6. Anonymous

    Thank you for this useful example. It´s quite good to understand the basic of swiz. 

    For a better understanding of the message handling it will be helpful to declare the click-handling-methode on the save-button in the section 'Dispatching and Handling Events'.

  7. Anonymous

    how did the click event of the button get bound to the saveUser function?

  8. Anonymous


    works with flex 3 sdk only for flex 3.5 or 4??

    1. All current development and testing is done under the 4.x SDK, but since there is nothing Spark-specific in the framework, it should work fine with 3.5.

  9. Anonymous


    I've been through this example before but there's some things I'm missing since a couple of releases ago.

    Does this currently work with 1.0 or does this only work with 0.6.4 or whichever release it includes in the example zip file?

    I would like to see an updated example if that's the case.

    Either way, I really appreciate all your work there, you guys really rock! SWIZ is for sure something you would like to follow as it grows.

    Cheers and happy holidays!

    1. It works fine with Swiz 1.0.

      1. Anonymous

        I realized it after reading a little bit further (silly and lazy me).

        Thanks a lot!!

  10. Anonymous

    Is there any page which indicates the changes and updates that have been made or are being made to swiz? ie. the Mediate to EventHandler. I would really appreciate if you take me there.

  11. Anonymous

    I have downloaded the zip and FXP files but there is no .html on the debug. Ho do I create it?

    1. It's created when you build the project.

  12. Anonymous

    it's very good.thanks!!