4.
Data exchanging between Action Script and FFish
Script
We often need to exchange data between Action
Script and FFish Script. In the section "Add
more functions to your application"
we discussed a sample about saving game scores.
The "flashplayer" and "score"
text fields are in Flash, how can we get their
values? And How can we transfer data from Action
Script to FFish Script or from FFish Script
to Action Script?
SWFKit provides 3 ways.
The most direct way to exchange data between
AS and FS is to use these two methods. In fact,
in all other two ways these two methods will
be called at last implicitly. The methods are
provided by the Macromedia Flash Player ActiveX
Object and SWFKit wraps them in the FlashPlayer
object.
In the game score sample, to get the value
of the "playername" and "score"
variables in Action Script
var playerName = FlashPlayer.getVariable("_root.playername");
var score = parseInt(FlashPlayer.getVariable("_root.score")); |
To fire the trigger, we need to set the "fArg"
property of the trigger component
| FlashPlayer.setVariable("_root.trigger.fArg",
allscores.toString()); |
You can read the SWFKit online documentation
to get more details for this method.
Still in the game score sample, to get the
value of the "playername" and "score"
variables using this method, firstly we need
to bind the variables in FFish Script
| FlashPlayer.bindData("_root.playerName",
"_root.score"); |
To get the values of the variables
FlashPlayer.updateData();
trace(FlashPlayer._root.playerName);
trace(FlashPlayer._root.score);
|
These four methods provide an easier way to
exchange arrays and objects between the Action
Script and FFish Script. The methods provide
a way to transfer arrays or objects by only
one call. However, you must declare the arrays
or objects in Action Script explicitly before
data exchanging.
|