JSFL, Javascript for Flash, supports running scripts from other script files. The syntax is not very lucky, and I would have preferred something like import, but its availability allows for creation of libraries for reuse.
The file Commands.zip contains “newItem.jsfl”, that contains a few functions that come in handy when creating a new linked movieclip item. The main function is createNewLinkedMovieClip, that creates a new movieclip symbol in the specified library with a specified linkage class. The user is prompted for a name that has to be unique both as symbol name and as linkage id. If the user cancels, the script is aborted. Here’s an example of how to call this function. This example assumes that the file has been placed in a folder “includes” inside the commands folder:
var library = fl.getDocumentDOM().library;
var movieclipName = fl.runScript(fl.configURI + "Commands/includes/newItem.jsfl", "createNewLinkedMovieClip", library, "org.asapframework.ui.buttons.HilightButton");
The function returns the name of the created movieclip symbol, or “null” if the user cancelled the prompt for a name. It would be logical to stop the script if the user cancels. Now aborting a running jsfl script isn’t entirely trivial. Apparently the only way to achieve this, other than wrapping every possible abort point in an increasingly deep if {}, is by using try{} catch (). Though more advanced in use, it has the nice effect of catching errors that would normally result in a popup from Flash, and displaying a useful message in the output window. That is, provided the error message is put through to the output window:
try {
// some code here that may go terribly wrong
} catch (err) {
fl.trace("Command aborted, error = " + err);
}
In order to abort a script, an error can be thrown that will be caught in the catch (err) {} statement, like this: throw("Cancelled");
The file also contains functions for writing frame labels on consecutive key frames, and creating an actionscript layer with a stop frame in the first frame.
The other two files in the zip are complete commands for creating stubs for the HilightButton and Checkbox classes from ASAPFramework.
Comment by MEMBRANE PER LAVORAZIONI SOTTOVUOTO
1 17 Dec, 2010, 12:00 o'clock |
Brilliant reading, kudos!