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.

Child pages
  • Module Support
Skip to end of metadata
Go to start of metadata

Parent and Child Swiz Instances

Swiz supports the concept of parent and child instances. Typically, this capability is used in conjunction with Modules. When you load a module that contains a Swiz instance as a child of another Swiz-based application, the framework will create a parent-child relationship between these two instances of Swiz. This happens automatically, meaning that the developer should not have to do any manual setup or configuration to use this feature. There is a sample application that demonstrates how Swiz can work with Modules at the Github repository.

Here is a graphical representation of how the module support works and what capabilities it offers:

The one main issue that developers encounter related to module support has to do with Swiz metadata-based event handling. The [EventHandler] metadata tag only contains a string value representing the event class and constant name. As a result, when Swiz attempts to validate the event, you will receive an error if that event class was not compiled into the Module. This is because Swiz cannot locate the event class in the ApplicationDomain. The developer must ensure that event classes defined outside of the module are included in the compiled module. In practice, this simply means adding a variable declaration somewhere that is typed to that event. As long as an actual reference to the event type exists somewhere within the module, that class will be compiled into the module. This allows Swiz to locate the class reference and validate the event constants.

Note that this is not actually a Swiz-specific issue. The compiler only includes classes that are actually referenced in an application; all others are discarded for optimization purposes.

The Local and Global Scopes

Swiz offers some additional control over how events are dispatched and handled between parent and child Swiz instances. Most developers will probably never need to concern themselves with this fine-grained control, but it is described here for the cases where it is desired.

The [Dispatcher] and [EventHandler] metadata tags allow for an optional attribute called scope, which can be set to "local" or "global". The default value for both of these attributes is "global".

If a [Dispatcher] metadata tag specifies scope="local", the dispatcher for that Swiz instance is injected. When scope="global" is specified, the dispatcher for the top-level Swiz instance is injected.

Similarly, if an [EventHandler] metadata tag specifies scope="local", only events dispatched through the local dispatcher are handled by the decorated method. When scope="global" is specified, events dispatched through the global dispatcher are handled.

Since this may make more sense when visualized, here is a graphic depicting the local and global scopes:

  • No labels


  1. Anonymous

    Hi, Possible bug I think.

    I'm using a PopUp window inside a module and [Inject] doesn't work in the popup mxml. Works fine outside of a module.

    Is this a know issue or do you want me to post my code somewhere?

  2. Anonymous

    It would be nice to have a simple example illustrating this theory.

    1. Anonymous

      Yes I agree. I can't find any examples of using modules with swiz. It's not a nice to have facility after all.

  3. Anonymous

    as of swiz 1.0RC1, injections can't be done in popups within modules. They're planning to include this in the final release. However, popups within popups might not be supported.

  4. Anonymous

    I experienced other flex framework many years, and working with modules and make them communicate is quite easy for me. After start learning swiz (it look interesting for me) and i have some questiong about module:

    1.Can a shell create multiple module object from the same class?

    2.Can shell or parent class communicate (dispatch a message) to only a specific module object (other loaded of the same class will not listen)?

    please guide me or give me some example. thanks

    1. There is an example of module communication in the Swiz Github examples repository. If you have specific technical questions, please ask on the mailing list.