Love editing your Flash ActionScript files in jEdit, this site but want better debugging tools within the editor itself? Maybe you’d like to jump directly to errors indicated within your code without resorting to the Flash IDE?
Today’s tip just makes me plain happy.
It may take a few minutes to set up, but it definitely shows off the power and expandability of jEdit — while also providing a heckuva nice (and long awaited) feature for us cross-platform Flashers.
First, it’s time to gather the ready-made ingredients:
- The Console plugin for jEdit
- The ErrorList plugin for jEdit
You probably already have these, but if not, follow the instructions in Part 1 of this series to get them set up with jEdit. This article merely builds on the original “Test in Flash” macro we created back when we started all this.
In fact, I’ll start the hand-made stuff with a new Test_in_Flash.bsh macro that can be typed into jEdit and saved directly to your jEdit macro directory (again, see Part 1 if this is confusing to you):
// Save this file to your hidden ~/.jedit directory as "Test_in_Flash_IDE.bsh" // This will cause the command to appear under the Macros directory as "Test in Flash IDE." // You can then assign a Shortcut key (such as CMD-ENTER or F6 a la FlashDevelop) // using jEdit>Preferences>Shortcuts>Macros // runCommandInConsole(view, "System", "rm -f ~/.jedit/flasherrors.tmp; open ~/.jedit/launchers/flashtest.jsfl ; sleep 2; cat ~/.jedit/flasherrors.tmp" ); // The following line just tidies things up. clearConsole(view);
The above code assumes you have a hidden folder named .jedit within your default user home folder (indicated by “~”), and a JSFL file (we’ll create it next) named flashtest.jsfl within a launchers subfolder of .~/jedit.
The macro’s operation is simple: It tells the Command Console plugin to execute code that first deletes a temporary file (if it exists), then launches the flashtest.jsfl within the Flash IDE. Next, the console shell waits a couple seconds to give Flash time to choke on any errors your code might contain, then it lists the contents of the new flasherrors.tmp which was generated when the JSFL file ran (more on this later). Finally, it clears the console to start again anew.
So what’s in the mysterious flasherrors.tmp file? It’s the output generated by the Flash compiler, in a format dictated by Flash itself. It’s generated by the ~/.jedit/launcher/flashtest.jsfl file, which should contain the following:
flash.getDocumentDOM().testMovie(); flash.compilerErrors.save( "file://Users/USERNAME/.jedit/flasherrors.tmp", true, true );
Man, I love the extensibility features of Flash! Thanks to JSFL, most of the hard work is already done for us.
Note: In the above code, be sure to replace USERNAME with your current system user name (The URL format used by the flash.compilerErrors.save() method does not allow for the “~” shorthand we’ve used elsewhere).
Confessions of a cheater:The output from the compiler is of interest to the ErrorList plugin, but not to us. Unfortunately, the ErrorList plugin does not actually monitor log files, but pays attention only to jEdit’s own “editBus” message system. We could write a proper Java plugin to send the info to the errorList, or we can simply do what I’ve done here: cheat and let an existing “editBus aware” plugin do the work for us.
The cat command in the beanshell (Test_in_Flash.bsh) script above does little more than spill the contents of the generated log file into the command console, which, coincidentally, is monitored through the editBus by the errorList plugin. Because the “spillage” is not much to look at, the last line of the macro itself simply clears the console view of the mess created by cat — but by then, both Console and ErrorList have already started conspiring together through the magic of regular expressions:
Now we just need to make sure Command Console recognizes the cat output so it can send a proper message to the ErrorList. We do this through the Plugin>Plugin Options…>Console>Error Patterns settings panel. Navigate to the settings and click the “+” (plus sign) under the list of Error Patterns. When you are prompted for a name, type “ActionScript.”
Next, type (or better yet, copy) the following regular expressions into the settings panel carefully:
Error Regexp: **(E[^*]+)**s+(.*)?,s+Lines+(d+):s?(.*) Warning Regexp: **(W[^*]+)**s+(.*)?,s+Lines+(d+):s?(.*) Filename: $2 Line Number: $3 Error Message: $1: $4
When you’re done, the panel should look like this:
Press Apply to confirm the settings for the Console plugin.
Next, while still in the Plugins options panel, navigate to the options for the Error List plugin and ensure that “Automatically display on error” and “Show error icons in the gutter” are both checked. This will allow for instant notifcation once the macro has run successfully.
Once that’s done, there’s nothing left to do but test it: Open an FLA file in Flash and an associated ActionScript file in jEdit, and test the movie using your new “Test in Flash” macro.
If you have an error in the code (you’ll probably have to introduce one on purpose, as I’m sure your code is usually flawless), you should see something like the following suddenly appear in the jEdit errorList panel (which you may want to make sure you dock somewhere on the screen):
If it’s not working… well, check your work, making sure you changed any usernames or filepaths to match those of your system (those presented here are particular to OS X, for instance). If you’re really stumped, drop a line and maybe we can figure it out together.