ActionScript and JSFL
Flash movies that run in the Flash MX 2004 IDE can execute a string of JSFL using a special ActionScript function. Which means that your Flash panels and XML2UI dialog boxes that contain Flash movie controls can modify/update the Flash document from a Flash movie. The JSFL code you execute can also return a value back to ActionScript. The ActionScript function is called MMExecute, and it can be used anywhere in your Flash movie.
The syntax is simple:
For example, I can create a new panel, as above, and in the Flash movie for that panel, I can execute a string of JSFL that will delete a layer when a button is pressed.
Here is the ActionScript to do it:
When the button is pressed, the MMExecute function passes the JSFL string as an argument to the Flash MX 2004 JSAPI Interpreter, which then runs the JSFL code in exactly the same way that a Command is run.
It is also possible to access the value of a JSFL property because the MMExecute function will return a value. So if I wanted to check that the computer running my Flash panel is currently connected to the Internet, I could use the following ActionScript:
In the above code, the ActionScript variable 'hasInternetConnection' will contain a Boolean value that it received from the JSAPI Interpreter.
MMExecute will wait for a return value before it runs the next line of code in your ActionScript.
It is recommended that if you want to execute a large JSFL script from ActionScript, you should place the JSFL script in an .jsfl file and then use the 'flash.runScript' function to execute the JSFL script within that file.
Here is an ActionScript function that will execute the JSFL code within a .jsfl file:
And you can use it like this:
Notice, that the fileURI in the above example, doesn't contain backslashes; it contains forward slashes and a file:/// protocol prefix.
The following would be incorrect:
This is a common mistake. All the functions that are exposed in the JSFL scriptsthat accept a fileURI as an argument, such as 'flash.saveDocumentAs'require the string to contain a file:/// protocol prefix and to contain forward slashes instead of backslashes.
One really useful implementation of MMExecute would be getting a Flash movie that is running in the Flash MX 2004 IDE to work with regular expressions. As ActionScript doesn't support regular expressions, it is possible to send them the JSAPI Interpreter using MMExecute and the return value(s) will be returned to ActionScript.