I just pushed a new sample application called SwizModuleExample-Flex4 to GitHub. This example is meant to demonstrate the various ways that Swiz supports the use of modules. The key ideas demonstrated are:
- Loading a Module
- Detecting full creation of a Module (not just the ModuleEvent.READY event)
- Dispatching events from a root Swiz instance that are mediated by all Modules
- Dispatching events from a root Swiz instance to a specific Module
- Dispatching events from a Module that are mediated in the root Swiz instance
- Dispatching events from a Module that are mediated by other Modules.
- Injecting Beans that are defined in a root Swiz instance into a child Swiz instance.
While this example is really meant to be looked through at the code level, I have a running version with View Source enabled that you can look at as well. I hope folks find this example helpful!
Comments (10) |
del.icio.us
|
Digg It!
|
Linking Blogs
| 5700 Views


# Posted By Cerli Rocha | 8/17/10 9:10 AM
Hi Brian,
i have problemns trying using swiz modules + MDI Window, you have any trick about?
# Posted By Brian | 8/17/10 9:43 AM
If you have a question, I would ask on the Swiz mailing list.
# Posted By AG | 9/13/10 12:22 PM
Hello Brian,
It doesn't seem to me that this example really demonstrates the ability to dispatch events from a Module that are mediated by other Modules. It looks like Module1Event is being dispatched from the main application and not from the module. I've modified your example to dispatch an event from module1 to be mediated by module2 and could not get it to work.
Your thoughts?
# Posted By Brian | 9/13/10 12:33 PM
When you press Dispatch An Event from Module 1, the root fires an event that is mediated by Module 1, and then Module 1 dispatches its own event which is mediated by the root application as well as Module 2.
# Posted By Kevin Yang | 11/8/10 10:11 AM
Hi Brian,
I have encountered a problem with using SWIZ.
I have tow modules and each of them has declare the "viewpack";
I use a 'moduleContainer' as show below(for add the modules).
<s:Group id="module1Container" width="100%" height="100%"/>
I also have a menu, when the Menu items be clicked, dispatch an event and a funcion handle it
public function MenuItemClick( name : String ) : void{
info = ModuleManager.getModule(name);
info.addEventListener(ModuleEvent.READY, moduleReadyHandler);
info.load();
}
private function moduleReadyHandler(e:ModuleEvent):void {
moduleContainer.removeAllElements();
moduleContainer.addElement(IVisualElement(info.factory.create()));
}
when I click different menu item. I want to show differnt module for the user. But now, the line of
'moduleContainer.removeAllElements();'
will throw exceptions:
ReferenceError: Error #1065: ?? null ????? Variable be null,or not defined?
at flash.system::ApplicationDomain/getDefinition()
at org.swizframework.reflection::TypeCache$/getTypeDescriptor()[E:\EAS\Admin\src\org\swizframework\reflection\TypeCache.as:55]
at org.swizframework.reflection::ClassConstant$/getConstantValue()[E:\EAS\Admin\src\org\swizframework\reflection\ClassConstant.as:101]
at org.swizframework.processors::MediateProcessor/parseEventTypeExpression()[E:\EAS\Admin\src\org\swizframework\processors\MediateProcessor.as:209]
at org.swizframework.processors::MediateProcessor/tearDownMetadataTag()[E:\EAS\Admin\src\org\swizframework\processors\MediateProcessor.as:122]
at org.swizframework.processors::BaseMetadataProcessor/tearDownMetadataTags()[E:\EAS\Admin\src\org\swizframework\processors\BaseMetadataProcessor.as:142]
at org.swizframework.core::BeanFactory/tearDownBean()[E:\EAS\Admin\src\org\swizframework\core\BeanFactory.as:339]
at org.swizframework.core::SwizManager$/tearDown()[E:\EAS\Admin\src\org\swizframework\core\SwizManager.as:89]
at org.swizframework.core::BeanFactory/tearDownEventHandler()[E:\EAS\Admin\src\org\swizframework\core\BeanFactory.as:457]
at flash.display::DisplayObjectContainer/removeChild()
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::$removeChild()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:6953]
at mx.core::UIComponent/removeChild()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:6860]
at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementRemoved()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Group.as:1467]
at spark.components::Group/removeElementAt()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Group.as:1222]
at spark.components::Group/removeAllElements()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Group.as:1236]
at com.kaidi.eas.admin.view::MainView/moduleEventHandler()[E:\EAS\Admin\src\com\kaidi\eas\admin\view\MainView.mxml:41]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at ModuleInfoProxy/load()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\modules\ModuleManager.as:1121]
at com.kaidi.eas.admin.view::MainView/MenuItemClick()[E:\EAS\Admin\src\com\kaidi\eas\admin\view\MainView.mxml:36]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at org.swizframework.metadata::Mediator/mediate()[E:\EAS\Admin\src\org\swizframework\metadata\Mediator.as:91]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:12266]
at com.kaidi.eas.admin.view::Menu/accordion1_clickHandler()[E:\EAS\Admin\src\com\kaidi\eas\admin\view\Menu.mxml:18]
at com.kaidi.eas.admin.view::Menu/__test2_click()[E:\EAS\Admin\src\com\kaidi\eas\admin\view\Menu.mxml:29]
If I remove the "viewpack" of the modules, it works OK, but can use injection in the view.
Can you give me some advice to solve this problem.
Thanks very much.
# Posted By Brian Kotek | 11/8/10 12:19 PM
If you have a question the best place to ask is the mailing list at http://groups.google.com/group/swiz-framework which will open the question up to more people than just me. ;-)
That said, first, you're not unloading the module, you're just removing the elements. According to the Flex docs, you'll need to set the info variable to null, and possibly call unload() and/or release(), and make sure that there are no references to the Module remaining.
You may also be having ApplicationDomain issues. Modules and ApplicationDomains are a vast and complex subject, so looking at this may help: http://www.senocular.com/flash/tutorials/contentdo...
Anyway, like I said try posting to the mailing list so that others can help and so that the problem and solution are recorded for anyone else who may run into it in the future. Thanks.
# Posted By Kevin Yang | 11/9/10 8:37 AM
Thank you very much. as you said, I unload the modlue and set the info variable to null. It works OK.
Next time, if I have any question, I will use the mailing list. Thanks again.
# Posted By Kevin Yang | 11/9/10 9:10 AM
sorry, I made a mistake, it may be an ApplicationDomain issues. because I will the debug flashplay version. the error message popup again. Any way ,thanks a lot. I will try my best to fix it by myselt.
# Posted By Faizuddin | 7/5/11 12:59 PM
Hi Brian,
We are developing a very large application, which contains different modules. Whenever user resize the browser, the injected beans are lost.
We are using swiz framework 1.0, I will appreciate your help.
# Posted By Brian Kotek | 7/5/11 1:44 PM
Hi, the best place to ask questions is the mailing list, where multiple people have the chance to respond. But to try and answer your question, the issue with resize events triggered by UIController causing tear down was addressed back in October, 2010. You can see part of the logic that handles it at https://github.com/swiz/swiz-framework/blob/master.... It sounds like you're still running the 1.0 RC, so the first thing I would do is update to the current version, 1.2. If the problem persists, feel free to ask on the Swiz list and we'll see what we can do. Thanks.