About Swiz + Modules

64 views
Skip to first unread message

Carlos Rovira

unread,
Oct 31, 2008, 7:16:45 PM10/31/08
to swiz-fr...@googlegroups.com
Hi Chris,

I'm new to swiz and want to know about the use of modules with swiz.

Could you tell us about the state of module functionality integration in swiz? I'm building large apps and can't enter a new framework without this kind of support/feature.

Some links regarding this concrete topic?

Thanks in advance and great work!

Best,

PD: btw, why don't configure the group in order to prefix the mail's titles like other groups. i.e: "[SWIZ]", this could allow us to identify the threads better in our inbox : )
Carlos Rovira
Director de Proyectos
carlosrovira.com
Avda. Betanzos nº2, 1º-3
28029 Madrid
+34 607226005
+34 912441351
http://www.carlosrovira.com

madsmao

unread,
Dec 10, 2008, 2:42:29 AM12/10/08
to Swiz Framework
I am new to both modular Flex applications and Swiz, but I am also
very interested in exploring the possibilities of using Swiz with a
modular Flex application. I am already researching this topic on my
own and if my findings are of relevance I will surely post them here.

Any feedback from the Swiz team on this topic would be greatly
appreciated. A few loose ideas or examples of implementation would be
even greater :-)

Sönke Rohde

unread,
Dec 11, 2008, 5:52:28 AM12/11/08
to swiz-fr...@googlegroups.com
Hi,

Swiz works fine with modules. Simply load your module beans on preinitialize like in the main application when you not use Autowire or Mediate in the module itself.
If you use Autowire or Mediate in the module you have two options:
Since the added event comes earlier as the preinitialize you either autowire the module manually after loading the beans or you use the added event in the module like this:

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300"
added="onAdded(event)">

<mx:Script>
<![CDATA[
import org.swizframework.Swiz;

// bean from ModuleBeans
[Autowire(bean="moduleModel")]
public var moduleModel:ModuleModel;

private function onAdded(event:Event):void
{
if(event.target == this)
{
Swiz.loadBeans([ModuleBeans]);
}
}

]]>
</mx:Script>

</mx:Module>

Cheers,
Sönke

madsmao

unread,
Dec 12, 2008, 3:37:33 AM12/12/08
to Swiz Framework
My own findings did indeed confirm that Swiz works great with modules.
I have further optimized my code by using your example to load beans
from within the module onAdded. Thanks a lot!

Prem

unread,
Jan 3, 2009, 9:04:29 PM1/3/09
to Swiz Framework
This is an old post but I was wondering if someone could clarify a
question about modules.

In my main application I have defined beans in Beans.xml. When the
application loads a configController loads external data and then its
made available through the entire application by autowiring
configController to the views.

If I want to access the same configController in my module how do I do
it. I tried Sonkes method of loading the same beans again in that
doesnt seem to work. There are no errors but the properties of the
configController seems to be reinitialized that is they are null.

So is this the wrong approach ? Should I be using the configController
referenced from the main Application?

Traboukos

unread,
Jan 11, 2009, 7:13:27 PM1/11/09
to Swiz Framework
Hi,

I am facing the same issues as Prem. I am trying to autowire
controllers that are created by the main application into modules and
I am getting null. What is really strange is that some time with
slight changes in the controller code I might get the autowire to
work. Changes like not declaring a local private variable in the
controller for example.

Any help on this would be greatly appreciated.

Sönke Rohde

unread,
Jan 12, 2009, 9:57:23 AM1/12/09
to swiz-fr...@googlegroups.com
Hi Traboukos,
can you please post some example code so it is easier to understand
your problem?
Is it only the Module class itself where you get no autowire or is it
a general problem?
Sönke

Prem Radhakrishnan

unread,
Jan 12, 2009, 10:29:11 AM1/12/09
to swiz-fr...@googlegroups.com
Sonke,
Here is my code

The main Beans that loads into the main Application looks like this


<?xml version="1.0" encoding="utf-8"?>
<BeanLoader xmlns="org.swizframework.util.*"
            xmlns:mx="http://www.adobe.com/2006/mxml"
            xmlns:controllers="com.tndn.controllers.*"
            xmlns:delegates="com.tndn.delegates.*">
   
    <controllers:MapController id="mapController"/>



Now if I do this in my MainUI.mxml file which is part of the main application it works fine

[Bindable]
[Autowire(bean="mapController")]
public var mapController:MapController;


If I want to use this in my module the same code doesnt work even if I load the same Beans.mxml file into the module.

What I have to do is pass a reference of MainUI.mxml into the module as a variable lets say mainUI and then reference it as mainUI.mapController


Cheers
Prem
--
A programmer is a device to turn coffee into code
http://www.39dn.com

Sönke Rohde

unread,
Jan 12, 2009, 11:00:43 AM1/12/09
to swiz-fr...@googlegroups.com
You do not have to load the beans again. Beans loaded in the main application should also be available in modules. Maybe you can provide a testcase which we can verify?
Can you please also post the code of your module?
Sönke

Dimitris Stefanidis

unread,
Jan 12, 2009, 11:01:41 AM1/12/09
to swiz-fr...@googlegroups.com
Hi Sönke,

I managed to reproduce the problem with the following simple code. When the button is pressed it tried to access the contentController which should have been injected into the module. The contentContoller is null resulting in an exception thrown. I managed to fix the problem at least for this sample (I am not sure if other problems are going to appear in a larger application) by using the -keep-as3-metadata+=Autowire,Mediate directive in the project compiler settings. Since I was using flex 3.2 sdk I thought that (according to the documenation found on google code) using the directive was not needed.

// Fille ContentController
// -----------------------------------------------------------------------------------------------
package controllers
{

import org.swizframework.controller.AbstractController;

   
public class ContentController extends AbstractController
{
    public function ContentController() { }
   
    public function testFunc():void{
       
    }
}
}

// Fille testmodule.mxml
// -----------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<mx:Module
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    width="100%"
    height="100%">
   
    <mx:Script>
        <![CDATA[
        import controllers.ContentController;
       
        [Bindable]
        [Autowire(bean="contentController")]
        public var contentController : ContentController;
       
        ]]>
    </mx:Script>
   
    <mx:Button click="{contentController.testFunc()}"/>
</mx:Module>

// Fille main.mxml
// -----------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" preinitialize="onInitialize()">


    <mx:Script>
        <![CDATA[
       
        import org.swizframework.Swiz;
       
        private function onInitialize() : void {
            // load up swiz beans
            Swiz.loadBeans( [ Beans ] );
        }
        ]]>
    </mx:Script>
   
    <mx:ModuleLoader url="testmodule.swf" width="600" height="400"/>
</mx:Application>


// Fille Beans.mxml
// -----------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<BeanLoader
    xmlns="org.swizframework.util.*"
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:controllers="controllers.*"
    xmlns:delegates="delegates.*">
       
    <!-- content controller -->
    <controllers:ContentController id="contentController"/>             
</BeanLoader>

Sönke Rohde

unread,
Jan 12, 2009, 11:06:08 AM1/12/09
to swiz-fr...@googlegroups.com
If you compiled swiz from subversion and you left out the compiler directive you have to add it manually in you you like you did. There is no harm at all for apps so the compiler directive does not affect anything in larger apps. If you use the latest swc 0.0.5 from google code it should work without explicitly setting the compiler directive.
Cheers,
Sönke

Dimitris Stefanidis

unread,
Jan 12, 2009, 11:10:31 AM1/12/09
to swiz-fr...@googlegroups.com
I am using the swiz-0.0.5-010609.swc downloaded from google code.

Thanks,
Dimitris

Prem Radhakrishnan

unread,
Jan 12, 2009, 1:14:09 PM1/12/09
to swiz-fr...@googlegroups.com
I am not quite sure what I was doing wrong but I got it to work now. I am compiling from the subversion and I added my compiler settings to the library project now and took them away from the main project and all my beans are autowiring correctly now.

I have one set of beans that are loaded in the main application and another set in the module and everything is working fine.

Cheers
Prem

flashvnn

unread,
Mar 9, 2009, 6:49:48 PM3/9/09
to Swiz Framework
Hi all,

Who can give me a simple Flex project code to see how Swiz work with
module ?
I really like Swiz framework and just have trouble when work with
module ?

Cheers

João Fernandes

unread,
Mar 11, 2009, 4:55:52 PM3/11/09
to swiz-fr...@googlegroups.com
Sorry for the delayed response. For now there is no 'support' for
modules. I've reported that issue already. The problem is that when Swiz
tries to resolve class names, it will only look for them in the
application and not in modules and then fail.

For now, just load your beans from within the main app and keep a
private reference to those events that need to be mediated.

Cairngorm suffers from the same problem.

João Fernandes

Prem Radhakrishnan

unread,
Mar 11, 2009, 6:54:01 PM3/11/09
to swiz-fr...@googlegroups.com
We are using Swiz with modules successfully. following Sonkes directions in an earlier thread we basically load module specific beans from within the module . Is that what you were looking for? for the added event for the module we basically do this


   private function onAdded(event:Event):void
            {
                if(event.target == this)
                {
                        Swiz.loadBeans([ModuleBeans]);
                }
               
            }

João Fernandes

unread,
Mar 12, 2009, 7:26:12 AM3/12/09
to swiz-fr...@googlegroups.com
Prem,

and are you able to properly mediate Events that are exclusively within
the module and not in the main application?

João Fernandes

Sönke Rohde

unread,
Mar 12, 2009, 8:48:51 AM3/12/09
to swiz-fr...@googlegroups.com
João,
what are you referring to? Do you think it doesn't work?
I had no problems using Swiz for a module project where the
annotations Autowire/Mediate work like a charm.
Sönke

Dimitris

unread,
Mar 12, 2009, 9:33:14 AM3/12/09
to Swiz Framework
Modules work very nice with Swiz and onAdded.
Just make sure on unloading the module to remove the event listeners
of the module. Because if you reload it later events will be executed
twice, or three times depending on how many times you have loaded that
specific module.
Message has been deleted

Prem Radhakrishnan

unread,
Mar 12, 2009, 9:53:20 AM3/12/09
to swiz-fr...@googlegroups.com
What did you do to remove all the event listeners? Remove them one by one?

On Thu, Mar 12, 2009 at 8:41 AM, Dimitris <sakell...@gmail.com> wrote:

Any idea when using modules when you load and unload a module and then
load it again events are triggers twice? or three, four times
depending on how many times you have loaded/unloaded the module?

Thanks for your great work


Dimitris

unread,
Mar 12, 2009, 10:01:34 AM3/12/09
to Swiz Framework
Well this was only a sample application with a single event in the
module, so yes i removed it manually.

On Mar 12, 3:53 pm, Prem Radhakrishnan <godsmustbcr...@gmail.com>
wrote:
> What did you do to remove all the event listeners? Remove them one by one?
>

Chris Scott

unread,
Mar 12, 2009, 11:34:58 AM3/12/09
to swiz-fr...@googlegroups.com
I am starting a modules based application now, I think what we need to do is add core listeners to Swiz for unloading modules to go through and unwire anything done within the context of that module. I have some ideas for long term, but I winder if we can do a short term solution similar to handling AIR windows, such as a registerModule call, which handles the unwire on remove.

If Sönke is around, maybe he has some ideas as well, he's been working with modules more recently than I have.

-Chris

Sönke Rohde

unread,
Mar 12, 2009, 11:47:32 AM3/12/09
to swiz-fr...@googlegroups.com
Yep, I think this has to be done by a manual call so something like
registerModule(model) where we can add an event listener for the unload event.
However, I need to try it out to say something valuable.

Sönke

João Fernandes

unread,
Mar 12, 2009, 1:41:55 PM3/12/09
to swiz-fr...@googlegroups.com
Sönke,

I'm talking about DynamicMediator problem with Modules and cohersion errors that I've posted in the past.
I think there is also the problem of Event Classes that are exclusively within a module and not available in the main app, it will always throw an error to any mediated function that targets that class.

try to load this module from an application that has no reference to SomeEvent.
It will always to fail to create the dynamic mediator since it will lookup in the main application for the class definition and not within the available modules.


<?xml version="1.0" encoding="utf-8"?>
<mx:Module
xmlns:mx="http://www.adobe.com/2006/mxml"

layout="absolute" width="400" height="300"
initialize="module1_initializeHandler(event)">

<mx:Script>
<![CDATA[
import event.SomeEvent;
import org.swizframework.Swiz;
import mx.events.FlexEvent;
import mx.controls.Alert;
private var e:SomeEvent;

[Mediate(event="event.SomeEvent.DO_SOMETHING")]
public function doSomething():void{
Alert.show('mediated');
}

protected function button1_clickHandler(event:MouseEvent):void
{
Swiz.dispatchEvent(new SomeEvent(SomeEvent.DO_SOMETHING));
}


protected function module1_initializeHandler(event:FlexEvent):void
{
Swiz.setStrict(true);
}

]]>
</mx:Script>
<mx:Button x="64" y="48" label="Button" click="button1_clickHandler(event)"/>

</mx:Module>

--

João Fernandes

Adobe Certified Expert
Adobe Community Expert
http://www.onflexwithcf.org
http://www.riapt.org
Portugal Adobe User Group (http://aug.riapt.org)

Sönke Rohde

unread,
Mar 12, 2009, 2:37:09 PM3/12/09
to swiz-fr...@googlegroups.com
I think I get it. But you get the cohersion errors only when the
module is loaded the second time?
Something like "cannot cast Foo to Foo@f4g23f4"?

João Fernandes

unread,
Mar 12, 2009, 3:39:08 PM3/12/09
to swiz-fr...@googlegroups.com
The cohersion problem was because I didn't have a swiz instance in the
main application that time, so if I reloaded the module, it would throw
that error.That been fixed , I started getting that problem regarding
events that live only within a module and can't be mediated since Swiz
can't find their definitions in the main application.

Another problem is unloading modules beans, if I have a controller with
a mediated function it isn't properly 'de-mediated' and keeping a
reference that prevents garbage collection.

As a workaround for now, I've always loaded my beans in my main app,
loading them as needed and keeping a private reference to needed events
(so beans and events are always in the main app) but in my opinion
modules should be totally independent.

Reply all
Reply to author
Forward
0 new messages