next up previous contents
Next: The updateData method Up: Data exchanging between Action Previous: Data exchanging between Action   Contents


The setVariable method and the getVariable method

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, you can declare two variables in Action Script, providing they are "playerName" and "score" in level 0,

To get the value of the variables from Action Script

score.playerName = FlashPlayer.getVariable(
    "_level0.playerName");
score.score = parseInt(FlashPlayer.getVariable(
    "_level0.score"));

To update the value of the variables in Action Script

FlashPlayer.setVariable("_level0.playerName",
    score.playerName.toString());
FlashPlayer.setVariable("_level0.score",
    score.score.toString());



Copyright ©2000-2010 Shanghai TopCMM Software Technologies. All Rights Reserved.