ActionScript Error #5001: The name of package ‘com.cjm’ does not reflect the location of this file. Please change the package definition’s name inside this file, or move the file
Description:
This ActionScript error is a very common one especially if you haven’t defined a good package and class structure. The simple answer is that you misspelled something in your package description or you saved the class in the wrong folder. (See example 1)
Another reason that you can get this error in Flash is because you have a Document Class and you have specified the classpath in the “Document class:” field and you have something different typed in your package. You might say well that is not possible. If your default classpath is defined in the AS3 setting then the file will compile and the class will work properly if you remove the classpath all together out of your package. This is not recommended because it is not good practice. Please review the example2 below.
Solution:
Check your paths in the package, class and ‘Document Class’.
Example 1
Bad Code
package com.ckm
{
}
Good Code
package com.cjm
{
}
Example 2
Good Code – Bad “Document class:” definition
package com.cjm
{
public class MyDocClass
{
public function MyDocClass()
{
}}}
Good Code – Good “Document class:” definition
package com.cjm
{
public class MyDocClass
{
public function MyDocClass()
{
}}}
And those are two ways to resolve ActionScript Error #5001
As Always – Happy Flashing
This issue was driving me CRAZY and nothing I found on the Internet helped. Finally I got mad enough that I did this, and it worked, hopefully it will help someone else.
In Flash CS5 I went to Edit > Preferences and selected the ActionScript category. I then went into the ActionScript 3.0 Settings and deleted the source path. This caused Flash to crash. Upon reopening, everything works great!
Good luck!
Matt’s comment totally fixed my issue. I was going *INSANE*.
My fla is located at: src/fla/components/EntryComponent.fla
My .as file is at: src/com/someClient/view/components
My .as package looks like: package com.somClient.view.components
In the Document Class field in Flash I’ve written: com.someClient.view.components.EntryComponent
***BUT*** I had specified the class path: src/com/someClient/view/components, when it should just have been src/
Thank you Matt, as well as Curtis for providing this forum. May you both ascend into heaven on chariots made of chocolate and feathers.
Than a lot for this useful error-blog!~ Helped me out too.
thanks curtis, your tips on resolving #5001 were error was exactly what i needed. the compiler error was driving me nuts.
Pingback: Action Script Error Repository » ActionScript Error #5001: The name of package ‘com.cjm’ does not reflect the location of this file. Please change the package definition’s name inside this file, or move the file
I found myself committing an error repeatedly. Whenever I started a new project it would come up again. The help I found didn’t suggested checking this. I put Document Class (or class path) reference too deep in my structure. So instead of putting it at the root – \myProject\, I’d point it to \myProject\com\\packageName. It should have been pointed to \myProject. Then it walks the package tree. I’m sure this is so obvious to everyone else, but it drove me crazy.
Everything was named correctly – package name, document class… the class path looked good too – except it was not pointing to the parent of “com.company.packageName”, it pointed to the whole enchilada.
I hope it helps someone out there save some brain power.
Thanks for kicking this off – like was said above: there doesn’t seem to be a lot of explanation around packages at the level I seem to understand.
Just a word of caution, I’ve noticed that removing classpaths in the AS prefs and in the document prefs doesn’t take if the file is still located at the old location. Example: was keeping a file in com.tests.as3tests moved the file to com.gibbitz.utils and made modifications. removed the com.tests references from the AS prefs, the document settings and from the library linkage. compiled with a 5001 error. I followed the link from the compiler errors panel and it took me to the old file. To resolve the problem I had to remove the file in com.tests.as3tests after that the compiler found the correct file and compiled correctly. Funny how as2 was not dependent on classes, but seemed to do this right…
Now that stopped working. I went into my AS3 preferences and removed the relative paths there to my package folders, and for some reason that fixed the problem…this time at least.
— Jeremy
Sorry to post so many different times. This time, to fix the error, I closed Flash, deleted my flp file, opened Flash, created a new one, and added all my files back in and after all that it compiled fine.
— Jeremy
I’ve actually run into a case today where removing and adding the files does not fix the problem. I really wish I knew what was causing this. Sometimes it compiles fine, other times not. I’ve tried closing Flash and re-opening it in the hopes that it might be some kind of cache issue, but that still doesn’t work. Once I find a true workaround, I’ll post.
— Jeremy
I found another cause for this annoying error. I tend to use project files a lot. Now you’d expect project files to store relative paths to the files that you add, but unfortunately, this is not the case. This means that any time you move your project folder, you will get this error 5001 because the files actually in the project are at the old location, not the one you just moved to.
In order to fix this, ANY time you move your project folder, you should probably remove all files from your project and then re-add them. This stinks, but it’s what fixed the error for me. I should also mention that this error was sporadic for me. Sometimes things worked just fine. Other times, I got several error 5001s.
— Jeremy
Thanks Alan. Changed it to read correctly.
publice in Good Code – Good “Document class:” definition, you might want to fix that 🙂
Nochnoy, glad I could help you out.
Happy Flashing,
Curtis J. Morley
Thanks!
You saved lot of nurons on my poor brain. There is literally no sources explaining classpaths for as3 newbies.