Flash CS3: Adding custom classes to MovieClips in the library

Thomas Viktil

Today I was tearing out my hair in frustration of a problem I just couldn’t seem to figure out. And the solution was just about as stupid as I had hoped it wouldn’t be.

The case was as followed: I’m putting MovieClips in a SWF for use as a library in another SWF (I’ll call it master SWF). The library SWF has a custom document root with a function that helps me return the MovieClips I need. Some of the MovieClips in the library are extended with custom classes.

When I tried to return a MovieClip from the library SWF I would get an error message saying the MovieClip doesn’t exist. Even if the class has been set up correctly, the package names are fine, and everything looks right.

The library SWF resides in the root, together with the master SWF. This way I can keep the same document root in both SWF’s and share classes between. The custom class for the MovieClip I tried to return is in package bb.page, and the name of the class is Frontpage.

In Flash I set the linkage to bb.page.Frontpage, compiled, and expected a positive result. But no. I tried moving everything down to root level, thus flattening the whole directory structure. Removed the package name from the Frontpage class and gave it a try. It actually worked. But it’s not an optimal solution because I don’t want to mess up the root directory with tons of files.

Moving everything back in to the directories they came from, I gave a stupid idea a try; renaming the MovieClip in the library. And guess what? Renaming the MovieClip from ‘Frontpage’ to ‘bb.page.Frontpage’ did the trick. I haven’t bothered trying to figure out why it’s like this, but it seems like it just is.

So, conclusion to this;

Make sure the name of the MovieClip is the same as the linkage class.

Example: class Frontpage resides in bb.page. Linkage class is therefore ‘bb.page.Frontpage’. This will also have to be the name of the MovieClip.

UPDATE August 12 2008

While at work today I spent a few hours figuring out how to deal with this problem and came to a new conclusion; what I’ve written in this article is wrong. I haven’t managed to come to a perfect solution, but good enough for the project I’m working on. I’ll be back later to write more about this.

In the mean time, and if you are looking for a solution to a similar problem, try searching for keywords like as3 asset managemt, resource management, external libraries and such. I found some articles that gave me a better understanding of what I’m dealing with.


Leave a Reply