Module (class)
Overview
Summary
The Module class is the base class for creating xJSFL Modules, which are collections of interrelated files grouped by folder, and managed by a central JSFL class - the actual Module itself.
Contents
Guides
See the following sections for detailed information on Module concepts and practical how-to code:
- Guides: Extending xJSFL
- Guides: Combining multiple scripts into stand-alone Modules
- Tutorials: Modules
API
The majority of the class' functionality is held in properties, and it's up to the developer to add functional methods as they see fit.
Module(name, properties)
Base module class used to create xJSFL modules
Note that the module name should be supplied as Sentence Case, and should match the Module's root folder name:
xJSFL/modules/Test Module
The following example creates a new empty Module with no additional functionality, other than the built-in properties:
var module = new Module('Test Module');
trace(module);
[object Module name="Test Module" path="xJSFL/modules/Test Module/"]
The following example adds a constructor function, and some basic functionality that can be called from ActionScript or JSFL as needed:
var test =
{
init:function()
{
trace('Module "xjsfl.modules.' +this.key+ '" initialized...');
},
megatrace:function()
{
trace('I am ' + this.key.toUpperCase() + '!');
}
}
test = new Module('Test Module', test);
test.megatrace();
Module "xjsfl.modules.testmodule" initilized... I am TEST MODULE!
Module properties
name
The name of the module
When the Module is created, the name should be supplied in Sentence Case, i.e. "Animation Tools".
The following example displays the name of a test Module:
var module = new Module('Test Module');
trace(module.name);
Test Module
key
The module's key in xjsfl.modules
The module key is the object property the module code will be stored within the core xjsfl.modules object.
When the Module is created, the name should be supplied in Sentence Case, i.e. "Animation Tools". The key of the module will be derived from this, by removing all non-alphanumeric characters and converting to lower-case.
The following example displays the key of a test Module:
var module = new Module('Test Module');
trace(module.key);
testmodule
uri
The URI to the module's folder
The uri property of the module is derived automatically from the Module name and path to the modules folder. Use this property to refer to assets or other filesystem-specific elements you need to manage within your module.
The following example displays the URI of a test module:
var module = new Module('Test Module');
trace(module.uri);
file:///E|/Projects/xJSFL/modules/Test%20Module/
path
The path to the module's folder
The path property of the module is derived automatically from the name and modules folder. Whilst you should use the uri property for loading and saving module-related files, path is useful for debugging and user-related messages.
The following example displays the (shortened) path of a test module:
var module = new Module('Test Module');
trace(module.uri);
xJSFL/modules/Test Module/
settings
The default settings Config object
An optional default settings Config object is created when the module is instantiated. This should be used to store persistant settings related to the module.
The following example displays the details of the settings object:
var module = new Module('Test Module');
trace(module.settings);
[object Config path="xJSFL/user/config/settings/testmodule.xml" nodes=0]
data
The default data Config object
An optional default data Config object is created when the module is instantiated. This should be used to store persistant data related to the module.
The following example displays the details of the data object:
var module = new Module('Test Module');
trace(module.settings);
[object Config path="xJSFL/user/config/data/testmodule.xml" nodes=0]