How do I add use Actionscript in a movie?
Added: 31 Jan 2009. Working examples for Java.
Rather than define the behaviour of buttons and movie clips by creating individual action objects you can write the event handlers in actionscript and use Translate to compile the code and add it to your movie.
String script = contentsOfFile(filename);
ASParser parser = new ASParser();
byte[] code = parser.parse(script).encode(movie.getVersion());
The script is compiled in a two step process. First it is parsed and then encoded for the version of Flash used in the movie. Depending on the statements used in the script the encoded data can added to either: an FSDoAction object to be executed when a frame is displayed:
new FSDoAction(code);
an FSPlaceObject2 object to define a set of event handlers for a movie clip:
new FSPlaceObject2(identifier, layer, code, "clip", x, y);
or to an FSDefineButton2 to define the set of event handlers for a button:
new FSDefineButton2(identifier, FSDefineButton2.Push, records, code);
Translate fully supports Actionscript 1.0.