Okay, for those of you getting ready to work with dynamic modules, I thought I’d share a few minor points I picked up on this past week.
Your application must include a reference to any interfaces the module implements.
<mx:Moudule implements"com.company.project.SomeInterface">
You’d want a reference to com.company.project.SomeInterface in your main app.
Likewise if the module has subclassed Module
public class MyModule extends Module
You’ll need a reference to MyModule in your main app as well.
There are compiler options to include these references, however I find it easiest to just declare a variable of the corresponding type.
i.e. var interfaceDef:ICustomInterface
If you find yourself wanting to create your own ‘View’ class in PureMVC it’s pretty straightforward. Just ensure that you subclass the controller as well.
Here’s a sample facade utilizing a custom view class…
protected override function initializeController( ):void
{
if ( controller != null )
return;
controller = CustomController.getInstance( multitonKey );
}
// Our custom View subclass in action
protected override function initializeView( ):void
{
if ( view != null )
return;
view = CustomView.getInstance( multitonKey );
}
And the custom controller…
public static function getInstance( key:String ) : IController
{
if ( instanceMap[ key ] == null )
instanceMap[ key ] = new CustomController( key );
return instanceMap[ key ];
}
override protected function initializeController( ) : void
{
view = CustomView.getInstance(multitonKey);
}
Finally, our custom View
public static function getInstance( key:String ) : IView
{
if ( instanceMap[ key ] == null )
instanceMap[ key ] = new CustomView( key );
return instanceMap[ key ];
}
In practice the view in initialized in the controller’s initializeController() method, so without subclassing your Controller you still maintain the standard View.