Flash & AS3 info, source, & experiments
FlashCS3 Class Path Oddities
I just spent the last 30 minutes wanting to pull an Office Space on my computer. It all boiled down to odd behavior related to setting the class path in Flash CS3. Allow me to save you from a similar frustration:
Let’s say I have an .fla located in “com.natejc.display.utils”. Since I’ll be using other classes in different packages, I set my class path to “..\..\” to get me back to the “com.natejc” level.
Now let’s say that this .fla contained a MovieClip in the Library that was linked to a class called “ImageLoader” in the “com\natejc\display\utils\” folder. So, I naturally set the linkage properties of this MC to “com.natejc.display.utils.ImageLoader”. Upon compiling, Flash kicks out the following error message:
5001: The name of package ‘com.natejc.display.utils’ does not reflect the location of this file. Please change the package definition’s name inside this file, or move the file. C:\src\com\natejc\display\utils\ImageLoader.as
What!? Yes it does! They match perfectly!! Well, I finally discovered that if I moved the ImageLoader.as file to any other location and changed the linkage appropriately, everything worked great.
Conclusion: If a class lives in the same location as the .fla file, the linkage is always simply the class name without any package prefix, regardless of what your class path is set to or how deep the file actually exists within this path.
However, this means that the movieclip in my library can never be copied and pasted into a different library without someone remembering to change the linkage. C’mon Adobe, even if it is in the same folder, I should still be able to utilize my class path and specify the full package in my MovieClip Linkage.
| Print article | This entry was posted by Nate Chatellier on June 2, 2007 at 4:35 pm, and is filed under ActionScript, Flash. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 4 years ago
why would you put your fla in your AS lib?
about 4 years ago
Good question
To say that the AS lib that I work with at my company is large, would be an understatement (in the world of Flash development anyway). I just checked, and it contains 13,576 files. Since there are a team of developers all working with these different classes, and since code re-use, inheritance, and polymorphism is extremely important to us, we’ve had to get pretty creative on how to go about doing this…
Actually, rather than write a very long winded comment, I think I’ll write an entire post about the methodology behind developing Flash apps in this type of environment (it might not be till later this week since I’m going out of town for work).
So hang tight, and we’ll talk more shortly
about 4 years ago
It’s not odd at all. The package name of the class starts at the root of the class path. Since you are setting your class path to com.natejc, Flash sees the file as being “display.utils.ImageLoader”. How would it know about com.natejc? It doesn’t magically look in parent directories til it finds “com” or something like that. You tell it where to start looking by setting the class path.
I agree with Felix though, that you should not mix your flas with your .as files.
about 4 years ago
Looking forward to hearing how you handle it. We use FlashDevelop, so it’s a simple matter to set a global classpath to point to the common library directory.
about 4 years ago
Sorry it took a little longer than anticipated, but I finally got around to posting how and why we organize things the way that we do. Check it out here: http://natejc.com/blog/?p=61
about 4 years ago
Well – I was wracking my brains with a similar problem – I had 2 .as files in one package, one directory deep. The first loaded, but the second threw up the same error you described. After pulling my hair out for ages I removed the classpath from the preferences – and it worked straight away.
Odd