We love you, but we're not IN love with you

Flash AS3: Rename Class Package component (MXP)

I recently had a need for a Flash tool that would search through all of the files in a project and rename a class package reference everywhere that it showed up. The reason is simple: I have a generic Flash project that I use as a starting point for all of my Flash builds. It has a lot of basic features built in, such as error handling, preloading, analytics, basic page and navigation setup, etc.  It saves me several hours of coding on each new Flash project. The only downside is that all of the AS3 class files are in a package called “com.sampleclient.” So, I spend about 20 minutes renaming this class package reference in the FLAs and the Actionscript files every time I start a new project.

Well, I created a handy component to automate the process and I thought I’d give it away for other people to use. Simply download and install the MXP file found here. Once you’ve done that and restarted Flash, you will see a new entry in your Commands menu cleverly called “Rename Class Package.” Click it and it will open the following dialog box:
Rename Class Package
Enter the old package name (the one you want to rename) and the new package name (the new name you want it to have). Uncheck the box if you want it to prompt you each time it tries to save changes to an FLA file. Click OK and a file browser dialog will open:

rename class package browse

Simply find the folder that contains your project. You want the folder you choose to contain both the FLAs and the Actionscript class files. It then gives you a final double-check dialog:

rename class package check

I added this because I found myself clicking through without paying attention and specifying my entire C: drive as the project folder. So, this is one last verification to prevent that sort of thing.

It then recursively searches all files in that folder (and all of its subfolders). It does a find-and-replace for that package name in all actionscript files. It also moves all of the files in the old package to a new folder that reflects the new package name. Then it opens all FLAs and updates all linkages, base classes and document classes. Please note that it does NOT search timeline code for references to a class package. You shouldn’t be putting anything like that on the timeline anyway.

Once it has finished, it lets you know which files were updated (in case you’re interested):

rename class package confirm

It also ignores Subversion folders in the project folder. So, if you use Subversion for your flash projects, it should play nice. The current version of this component does not work with the XFL format, however. Sorry. I tried adding that functionality,but the script ran out of memory and crashed every time. I think it choked on all of the extra files and folders that are created by an XFL file.

This component does have one bug. After moving all of the Actionscript files to the new package folder, it should delete the old package folder, but it doesn’t. I don’t know why, but if I figure it out, I’ll update the component.

Hopefully, this will save you some time as well. If you want more details on how I built this, I will be posting info and source files soon. If you have any feedback for me, leave it in the comments. Thanks.

Previous

Flash CS5: TLF textfield bugs (or TLF WTF?)

Next

Writing a JSFL component for Flash AS3

3 Comments

  1. flashDevelop has a project-wide find and replace in files and a start at actual refactoring – have you tried it? It is free, and does other things I need often such as CSS, PHP XML and MXML editing. Many times I can tweak a file without opening another IDE. Use a Mac? Sorry, never mind…

    You are ranked #2 in Google today after a t-shirt company. #2 ranking is more fitting than #1 for the title of your blog so rejoice. yeah.

  2. admin

    To be honest, I’ve tried FlashDevelop a few times and was not that impressed with it. Maybe I’ll give it another look. I’m currently using Netbeans to do all of my PHP, HTML, CSS work. My Google ranking is usually #1, but I haven’t been posting as much lately – I’ll have to work on that. 😉

  3. Vlad

    Can you make a FD plugin ?

Powered by WordPress & Theme by Anders Norén