ASUL scripting

As of December 2010 the ASUL framework supports user scripts, by using the D.eval library to evaluate script blocks defined in ASUL definition files. This functionality is available in the MegaZine3 engine as of version 2.0.11.

For a detailed specification on the supported script features, please refer to the D.eval documentation. But in short it can be said: the scripts are ActionScript 3.0, with the only difference that a) it is not possible to declare classes, and b) function declarations do not use types, i.e. it's more like JavaScript in that regard.

= Adding scripts to ASUL =

To add a user script to ASUL, it is possible to use  blocks in the ASUL definitions. Depending on their location, they behave slightly different in regard to when they are run. Consider the following ASUL file:

Together with this AS3 code:

Both buttons will work fine. The difference is when the code in the script blocks is evaluated. Running this will result in the following output: start load [Thu Dec 23 2010 04:53:56 PM] SYSTEM [D.eval] init block 1 done loading [Thu Dec 23 2010 04:53:56 PM] SYSTEM [D.eval] init block 2 [Thu Dec 23 2010 04:53:56 PM] SYSTEM [D.eval] init block 2

Top level script blocks will be evaluated while the ASUL file is parsed. Script blocks nested inside ASUL definitions will be evaluated whenever the object is created. Note they will be run every time the container object is created.

Lastly, script in the so called event attributes will be run whenever the corresponding event takes place.

Whenever the script in such an attribute is evaluated, a variable named  is made available in the script context. This variable will be the original ActionScript3 event variable representing the event.

In general it is possible to put any code whatsoever into event attributes, but for readability and reuseability it is recommended to define the actual handler functions in script block and then calling that function.

= MegaZine3 specifics = In general it is possible for the environment to specify variables that are available in the global script context.

MegaZine3 does this and provides one or two variables, depending on the file:
 * in all ASUL files a variable named  is available (with shortcut alias  ), which is a reference to the   instance that loaded the files.
 * in all plugin ASUL files (i.e. all except ) a variable   is made available, which is a reference to the plugin to that the ASUL definition belongs. For example in the case of the gallery plugin it will be a reference to the   instance that belongs to the   instance.