views:

375

answers:

3

Does anyone have insight into when to use mx.modules.ModuleBase over mx.modules.Module? The documentation that I have seen isn't very clear on what each was designed for. What do they mean by "interacts with the framework" exactly? Does it just come down to visual vs. non visual components? Obviously a BaseModule which doesn't interact with "the framework" isn't going to be very useful so any realistic subclass of BaseModule would probably interact with the framework in some capacity. My guess is that Adobe provided ModuleBase so that developers could extend from the minimal amount of code necessary to just get something loaded into the vm at runtime. Any ideas? Thanks

Flex Developer's Guide pg.990

Extending the Module class is the same as using the tag in an MXML file. You should extend this class if your module interacts with the framework; this typically means that it adds objects to the display list or otherwise interacts with visible object.

... they go on to say

If your module does not include any framework code, you can create a class that extends ModuleBase. If you use the ModuleBase class, your module will typically be smaller than if you use a module based on the Module class because it does not have any framework class dependencies.

A: 

ModuleBase is for non-flex modules.

Module is for flex based modules. If you're using any flex components inside your module, this is for you. Or if you intend to use the module inside a flex app, you probably want this as well.

Marc Hughes
A: 

According to a comment inside of the ModuleBase.as file:

The base class for ActionScript-based dynamically-loadable modules. If you write an ActionScript-only module, you should extend this class. If you write an MXML-based module by using the <mx:Module> tag in an MXML file, you instead extend the Module class.

... and within Module.as:

If your module does not include any framework code, you can create a class that extends the ModuleBase class. If you use the ModuleBase class, your module will typically be smaller than if you create a module that is based on the Module class because it does not have any framework class dependencies.

So basically, if you are writing an MXML component, or if you are using flex framework classes, then you should use the Module class. Otherwise, ModuleBase is more appropriate.

Nik Reiman
A: 

Very cool, thanks everyone. Yes, I've read those comments as well. As I've worked with Flex modules over the past couple months I believe my original interpretation was fairly close "...Adobe provided ModuleBase so that developers could extend from the minimal amount of code necessary to just get something loaded into the vm at runtime." I feel that the doc's explanation is too general though. For example I have several ModuleBase classes that "interact with the framework". They are not visual components themselves - but utilize various framework classes to fulfill a kind of service role in my applications. I think that a more accurate description of ModuleBase would be to say that "If your module is not a DisplayObject then extend from ModuleBase".

smonaghan