Writing a JSFL Script
You create a JSFL script like you would an external ActionScript file. Using your favorite script editor, you write your JSFL code, then you save the file with a .jsfl extension. You can call the file whatever you like as long as it has the correct file extension.
You can also open JSFL scripts for editing in Flash MX 2004. Naturally your JSFL script will automatically open for editing in the JSFL Script Editor. To edit a JSFL script in Flash MX 2004, open the File menu and then select Open. From there, navigate through your local machine to find the correct JSFL script to edit.
|Figure 2. Purpose: Rollover a particular method or property for a brief explanation of its purpose.|
As with the ActionScript Editor, the JSFL Script Editor also contains a list of every object and each object's available methods and properties along the left-hand side. This does come in very handy, as there are a lot of them to remember. Rollover a particular method or property on the left-hand side and you will get a tool tip which will briefly explain what that particular method or property does. The JSFL Script Editor also has syntax highlighting and code hinting.
Executing a JSFL Script
To execute a JSFL script, the Flash MX 2004 IDE must be open. The simplest form of a Flash extension, the Command, has its own special place in the Flash MX 2004 IDE. That is the Commands menu:
Figure 3. The Commands Menu: Run Command from the Commands menu to execute your scripts.
Figure 4. My JSFL Scripts: The Commands menu will show your personal JSFL scripts. Select a name to execute the script.
When you select Run Command from the Command menu, you can locate a JSFL script to execute. The Commands menu displays three default options, shown in Figure 3, but it also adds a new option for each JSFL script. This new option is contained within a special Commands directory in the Flash MX 2004 Configuration folder. The location differs with different operating systems:
Windows XP or Windows 2000:
C:\Documents and Settings\ <user>\Local Settings\Application Data\Macromedia\Flash MX 2004\
C:\Windows\Application Data\Macromedia\Flash MX 2004\
Hard Drive/Users/ <username>/Library/Application Support/Macromedia/Flash MX 2004/
So, if you place your JSFL scripts in this directory, you can execute them directly from the Commands menu, by selecting the name of your script file from the list of options.
As shown in Figure 4, I presently have four JSFL scripts located in my Configuration/Commands directory, with the following filenames:
- Batch Run.jsfl
- Save Copy As.jsfl
When a JSFL script is executed all functions that are called update the state of a particular element in a Flash document immediately, which differs from ActionScript execution. For example in ActionScript, if you move a Movieclip across the stage in a for loop, you would only see the final state of the loop, as the stage is not updated until the ActionScript has been executed. However, if you were to call the 'deleteLayer' function of a timeline object in JSFL inside of a for loop, the layer is immediately deleted and the authoring environment will refresh to display the new state of the timeline before the code after the for loop is executed.