ModuleBase vs. Module - apache-flex

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.
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".

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.

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.

Related

Gluon Client Maven Plugin: Which type of classes should be specified under 'reflectionList' configuration

In the official documentation of Gluon Client maven plugin, the 'reflectionList' section is explained as
List of additional full qualified classes that will be added to the default reflection list, that already includes most of the JavaFX classes.
Tbh, it doesn't clearly explain what type of classes should be added in 'reflectionList'. In a pom.xml file of a gluon sample some of the classes in that project are not specified.
So, what kind of classes do we have to specify in 'reflectionList'?
You only have to add classes which are loaded via reflection. This happens for example when you are using FXML. It's mostly a try and error game unless you are following a more systematic approach and use the GraalVM native-image agent.
In most cases, controllers for FXML views created in Scene Builder. In the FXML file you specify what class should be a controller for a view generated from this file, and in that controller class you put fields and methods which are linked to elements in FXML. Sometimes, unfortunately, if you use a certain JavaFX widget in FXML you will also have to specify it on the reflection list (happened to me with javafx.scene.control.TitledPane).
There is way to make it more fine-grained and specify certain methods instead of all classes, but I wouldn't recomment it. Please take a look here for details: How to solve fxml loading exceptions in compiled JavaFX project using GluonHQ client, Native Image and GraalVM?
My solution is to keep FXML simple and enrich it with additional styles, register methods on actions (unless they are straightforward, like onClick), etc., in the code, so that I don't have to deal much with reflection.

Custom Components in Scenebuilder 2.0

In Scenebuilder 1.1, you could import an entire custom component as a whole.
In 2.0, however, it is importing the component as separate pieces (Container and nodes). Since my custom component relies on being unified to work with its controller and IDs, this breaks it.
Is there anything I can do as of yet? I'd really like to be able to use Java 8 and Scenebuilder 2.0 for its DatePicker. If a full stable release is right around the corner, perhaps I can wait. I'd preferably want to avoid hacky solutions.
Any ideas?
I have only found one way to deal with this kind of back-compatibility: building my own scenebuilder.
It is officially open source so you can check it out with mercurial on bitbucket for instance.
Then you build it and modify it to put all your custom components and dependencies in the same classpath for one unique classloader.
Check the class named FXOMLLoader, it is where the classloader is used, my fix was to explicitly only use one classloader for all components and adding a few repertories with my deps inside to the classpath for it to work.
I have used Jar Class Loader library to do so, and it works pretty well. This is pretty hacky though.

The meaning of "External" linking mode in Flex Builder

There are three modes to link an SWC library to a flex application: "Merged into code", "External" and "RSL". I understand what is "RSL", but I don't understand what is "External".
"RSL" works just fine for me, without any code changes. However, External doesn't work for me. Although my application starts, the classes in the SWC set to External are never found.
What is the meaning of "External" if it is not "RSL" ? How do I make use of that ?
Thank you,
Boris
Defining a class as External allows the Flex compiler to link to a particular class at compile time but does not cause it to be included in the generated SWF.
The general use for External classes is where you have multiple modules that use a shared library. It would be redundant to include the shared class definitions in every single module and the External keyword allows you to control how these classes are compiled into your libraries.
More information is available at the following locations:
http://web.archive.org/web/20101007120528/http://www.wannaknowflex.com/2010/05/flex-linkage-difference-between-rsl-and-external/
http://www.flexafterdark.com/docs/Flex-Libraries
(external-library-path and load-externs compiler information):
http://www.newtriks.com/?p=802

inside package

Similar to the [Embed ()] tag I know from flex ¿ what's for the following code:
[Event(name="init",type="flash.events.Event")]
[Event(name="ioError",type="flash.events.IOErrorEvent")]
[Event(name="securityError",type="flash.events.SecurityErrorEvent")]
I've found this in several libraries I used, the one show here is from Flartoolkit, the code is defined inside the package, after the imports.
By the way, is this code executed when I compile in flash IDE?
Thanks,
.am
That's actionscript's metadata tags. These specific ones declare that the class below them throws these kind of events of these types.
http://livedocs.adobe.com/flex/3/html/metadata_3.html#159710
This metadata gets bound to the class at runtime and is available for access
[Event] metadata is for the Flex framework and are not used by the Flash IDE, but you can use of the [Embed] metadata under Flash CS4

What's the difference between the mx/fx/s object types in Flex 4?

Flex4 provides the following namespaces:
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
What's the difference? Which namespace provide which function? Where can I find info about that?
Namespaces allow you to specify to the compiler where to look for the files/classes that you reference in your mxml.
There are two different types of namespaces that get used in Flex 4. A language namespace and a component namespace. the http: //ns.adobe.com/mxml/2009 namespace specifies what version of the mxml language gets used. This includes things like the script tag and binding tag as well as new tags like declarations and private.
The other 2 namespaces you reference above are component namespaces. These are references to the specific ActionScript classes that make up the UI components you will use in your application. The /flex/spark component set is the new flex 4 components which have skins and component implementation seperate. The /flex/halo set are the components that exist in the flex 3 set. Be careful though the /flex/halo has been renamed /flex/mx in new nightly builds.
In Flex 3 there was only one language available and only one component set so they jammed the definitions for those together in one file. So while the technical bits under the hood have not changed, the way adobe exposes them (through multiple namespaces) has. This may seem more complicated at first, but keep in mind that in doing flex work you have always created xml namespaces for all your view components in mxml. So now you play on the same level as the core framework, which is great. Also in Flex 4 there are several languages and component sets that can be used, so it would be impossible to create that one-to-one mapping that existed in Flex 3.
For more information on this topic please refer to the Adobe docs on the subject: http://opensource.adobe.com/wiki/display/flexsdk/MXML+2009
HTH,
sim

Resources