Global functions and variables

Categories:Framework basics, Core

Initialization

The framework must be initialised every time you want to run xJSFL code using the following command.

xjsfl.init(this);

Once initialized (see xJSFL Environment for more details) the following global functions and properties will become available, along with any registered classes or custom global functions:

Global variables

All xJSFL global variables start with a $ to differentiate them from any local variables you create.

Note that all these variables are JavaScript 1.6 getters, which means internally, they are actually calling a function, so if you plan to do a lot of DOM manipulation, for example, assign the result of $dom to a variable called dom, that way the behind-the-scenes methods are only called once:

var dom = $dom;
dom...
dom...
dom...

Get the current document DOM:

$dom; // same as fl.getDocumentDOM()

Get the current document Timeline:

$timeline; // same as fl.getDocumentDOM().getTimeline()

Get the current document Library:

$library; // same as fl.getDocumentDOM().library

Get the current document selection:

$selection; // same as fl.getDocumentDOM().selection

Note that you can use $selection in a for...each loop without it being called multiple times, as it would be in a for loop:

for each(var element in $selection){ ... }

Global functions

For convenience, there are various functions that have been made global.

Output

Trace output to the output panel:

trace('This is a trace', 'which handles', 'multiple arguments');

Clear the output panel:

clear();

Format some output to the Output panel:

format('The item "{name}" has {frameCount} frames', item);
The item "Symbol 1" has 25 frames

Inspection and debugging

Inspect any object to the output panel using Output.inspect():

inspect(window);

List the properties of an Array using Output.list():

list($selection);

Debug function, file URI, or caught error, using xjsfl.debug:

try{ x += 1; }
catch(error){ debug(error); }

Library / class loading

Load a class, but only if it's not been loaded yet:

include('Animation');

Force the load of a class, even if it's been loaded before:

require('Animation');

File

Load a file or execute an external JSFL script:

var text = load('path/to/file.txt');

Save some data to a file:

save('path/to/file.txt', 'some data');

Both functions call methods on xjsfl.file. See the section on File handling  for more info about loading files within the framework.

Next Steps

Comments are closed.