Anyone out there has an idea of how it was done ?
I read the MXI file in the FileSystem MXP but couldn't get any clue...
You can use the flash.runScript method to include another jsfl script
as a library. Unfortunately, there is no #include directive, but
runScript can work if you take care to declare your functions as
functionName = function(...) {...}
instead of
function functionName(...) {...}
Here's an example. The two files are library.jsfl which contains all
of your functions you want to reuse, and myCommand.jsfl which is some
script that will use the functions in library.jsfl. The files are in
the same directory.
// library.jsfl
sayHello = function()
{
fl.trace("Hello World.");
}
// end of library.jsfl
// myCommand.jsfl
fl.runScript("file:///library.jsfl");
sayHello();
// end of myCommand.jsfl
Notice that the URI is a relative path. You could also say
fl.runScript("file:///../../shared/library.jsfl");
or the more standard absolute path
fl.runScript"file:///D|/dev/jsfl/shared/library.jsfl");
I have also used shared jsfl scripts to extend some base objects. For
example, to add some useful functions to the String object, you could
make a file String_extend.jsfl
// String_extend.jsfl
String.prototype.lstrip = function()
{
for (var i = 0; i < this.length; i++)
{
if (this.charCodeAt (i) > 32)
{
return this.substr (i, this.length);
}
}
return this;
}
String.prototype.rstrip = function()
{
for (var i = this.length; i > 0; i--)
{
if (this.charCodeAt (i) > 32)
{
return this.substring (0, i + 1);
}
}
return this;
}
String.prototype.strip = function()
{
var s = this.lstrip();
return s.rstrip();
}
// end String_extend.jsfl
// myCommand.jsfl
fl.runScript("file:///String_extend.jsfl");
s1 = " This is a test ";
fl.trace(s1);
fl.trace(s1.length);
s2 = s1.strip();
fl.trace(s2);
fl.trace(s2.length);
// end myCommand.jsfl
It's interesting to note that the Flash Javascript interpreter seems to
keep variables persistent for as long as Flash is running. That means
you could run some command at initialization that defines all the
functions in your library and extends any objects you need extending,
then all subsequent JSFL scripts will have access to these methods even
without explicitly including them with the fl.runScript method. (Try
it yourself by running the scripts above, then commenting out
fl.runScript(...), just to make sure I'm not crazy.) This could be
dangerous if you have a command that overrides a standard method.
Subsequent calls to this method will be altered until Flash is
restarted.
I hope this helps.
--Dennis
Cheers !