Module (class)

Categories:OOP

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:

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

Parameters:

  • name string The name of your module - this should match the folder path
  • properties object The properties and methods of the object. Supply a constructor with "init:function(){ ... }"

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

  • Type: String
  • Access: Write

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

  • Type: String
  • Access: Read

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

  • Type: String
  • Access: Write

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

  • Type: String
  • Access: Read

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

  • Type: Config
  • Access: Write

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

  • Type: Config
  • Access: Write

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]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>