Ludicrous Software

JSFL to Bulk Rename Classes in a .fla

Here’s a super-simple JSFL script to rename a large number of Classes in the library of a .fla file. This is useful if, for example, you have a large number of audio files in the library. An easy way to give them all a unique class name is to select them all in the library, right-click and choose ‘Properties’ from the context menu, and then click the ‘Export for ActionScript’ button.

There’s a downside, though, which you’re familiar with if you’ve done this before. Flash Professional uses the item’s name as its class name. So if you do this to, say, a large number of audio files, you get something like this:

This is a problem because class names with a period in them make Flash cry. You could go through the library and change each class name one by one, but that’s kind of tedious. So, JSFL to the rescue! This little script will go through all of the items in the library and remove the last four letters from the Class name:

var itemArray = fl.getDocumentDOM().library.items;
for (var i = 0; i < itemArray.length; i++) {
    var item = itemArray[i];
    var className = item.linkageClassName;
    className = className.substring(0, className.length - 4);
    item.linkageClassName = className;

As you can see, it’s pretty straightforward. The actual renaming part is just a basic JavaScript substring() call, so you can easily customize this to your specific needs.