Publish Hooks library for Flash


A topic came up in the CS7 Beta pre-release channel yesterday about adding a new feature to Flash, Publishing Hooks. The idea was that 2 new file pickers would be added to the Publish Settings dialog:

  • Execute before publish
  • Execute after publish

This would allow the user to do some pre-publish cleanup, or some post-publish action, such a uploading a file.

The thing is, however, we can do this right now inside of Flash with Events!

It took me about 10 minutes to whip up some proof-of-concept code, another 5 to add an interface, then another 5 or so to ensure the UI saved and loaded settings, then about an hour or so to create a class out of this lot, add in some extra flexibility, some comments, and say "That'll do".

You can take a look at the source code as a gist on GitHub.

Here's the UI written in one line of code (including populating already-defined values) using xJSFL's XUL class:

Compare that to the amount of time it would take to request the feature, have it accepted, implement it in C++, along with any QA and the rest, plus the fact that once it's in, there's no flexibility - and I think you can see you have a pretty powerful argument for implementing some things in JSFL.

The final class does the following:

  • Runs pre and post publish hooks (any file on your hard drive, even other JSFL scripts)
  • Has a simple XUL UI to browse for files
  • Can load and save different profiles, say one for games, one for web
  • Stores setting in an XML config file (but could just as easily store those settings per document using document data)
  • Can be set as Active or Inactive should you decide you need to disable it

It's instantiated as simply as possible, like so:

// instantiate a "games" profile
    var hooks = new PublishHooks('games');

// bring up the ui

The config for all profiles is managed by the Config class, and stored in a single file in the xJSFL/user/config folder:


And here's a quick screenshot of a basic JSFL script being run right after publishing:

If you want to use the class, ensure you have the latest xJSFL from the repo (as the Event types have been updated) and download

The file contains both the class (save to your xJSFL/user/jsfl/libraries folder to run at startup) and a script to pop up the editing UI, which you can run as a Command from the Flash Commands folder or as a Snippet from the xJSFL Snippets folder.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>