2.
FFish scripting language getting start
Content
You can use FFish scripts in your projectors
or screen savers by two ways.
This command evaluates an expression. E.g.
The FFish script expression 'Dialogs.msgBox("Hello
world")' displays a message box. If you
want to use this expression in your projectors
or screen savers, insert a "FFish_Eval"
command into your movie

This command loads and executes a pre-compiled
script. To launch a "hello world"
message box is very simple, as you see, it needs
only one line of FFish Script code. However,
when you're working with a more complex job,
the "FFish_Eval" command isn't too
convenient for you. For maybe you need to write
hundreds of lines of FFish Script code. In this
case, you can use the "FFish_Run"
command.
Firstly, you can edit a new script in the SWFKit
script editor. Then you can call the script
using the "FFish_Run" command to call
it from within your Flash movies.
SWFKit will compile the FFish scripts to byte
code and pack the byte code into the output
executable files. That is to say, FFish Script
has high performance when calling by the "FFish_Run"
command. The FFish Script code called by "FFish_Eval"
is written directly in Action Script and SWFKit
cannot compile it to byte code, so the "FFish_Eval"
command runs slower than the "FFish_Run"
command.
E.g. read a line from a text file and show
the content in the text field.
- Create a new movie named "testrun"
with Macromedia Flash MX, insert a text filed
to display the content of the text file

- Add a FSCommand "FSCommand('FFish_Run',
'ReadLine');" to Frame 1. The command
loads and executes the FFish Script "ReadLine".
The "ReadLine" script must open
the specified text file, read one line from
the text file and change the content of the
text field in the "testrun" movie.
- Export a SWF movie "testrun.swf".
- Edit a text file named "testrun.txt"
with notepad. Our sample will read from it.

- Convert the "testrun.swf" to "testrun.exe".
The "testrun.swf" movie cannot read
from a text file, we must use SWFKit to extend
its power. Create a new project named "testrun"
using SWFKit, add the "testrun.swf"
to the project
- Add the "testrun.txt" into the
project
- Edit the "ReadLine" script in
the script editor (Using the Insert->New
Script command to insert a new script then
changing its name to ReadLine).
| //ReadLine -- a demo for using FFish
Run
//extract the text file
var path = getAdditionalFile("testrun.txt");
//open the text file and read a line
var stream = new FileStream(path);
var str = stream.readLine();
stream.close();
// change the content of the text
field in the swf movie
FlashPlayer.setVariable("_root.test",
str);
|
- Build and test it!

SWFKit automatically inserts a script named
"Initialize" into your project. You
can not rename or delete the "Initialize"
script.
The "Initialize" script is designed
to do some initializing works. The script is
executed only once just after the main window
of the projector is created and before the projector
has loaded a movie into the flash player. The
Initialize Script is the first executed script.
Functions and variables in the "Initialize"
script can be "seen" in any other
scripts.
Notice
A return of a Boolean value "false"
of the Initialize script exists the main program.
It’s highly recommended that returns true
explicitly at the end of the Initialize script
to ensure that the main program will continue
to run.
Tips
You can write some codes in the "Initialize"
script to prevent another instance of the same
application from running:
| //Initialize
//Finds windows with the same name as
this window
var wnds = Window.getWindowsByName(your
window name);
trace(wnds);
//Checks if there is another window has
the same name as this one
var w = getMainWnd();
var has = false;
for (i = 0; i < wnds.length; i++)
{
if (wnds[i].handle != w.handle)
{
has = true;
break;
}
}
if (has)
{
wnds[i].bringToTop();
return false;
}
return true;
|
|