Tuesday, December 04, 2007

The class 'com.your.class' cannot be imported because its leaf name is already being resolved to imported class 'com.your.class'.

While I was refactoring some ActionScript2 code, I ended up with the above error message.
I searched the web and what I came up with was mostly the information that such a message actually exists.
so after figuring out why I got that error I decided to write about it here for your benefit. (Leave me a comment if it helped you).

well it turns out that this was cause by the following proccess:
I have an adbode flash source .FLA file which had inside its _root code two #include statements:

lets say
#include "fileA.as"
and
#include "fileB.as"

now each of those file in its turn had an import statement
import MyClass
where MyClass.as was a file that was on the same directory as the .FLA, fileA.as & fileB.as.

It worked fine.
But when I started refactoring and moved MyClass to become com.whatever.MyClass
(with all the required changes to MyClass, fileA and fileB) I suddenly got
"The class 'com.whatever.MyClass' cannot be imported because its leaf name is already being resolved to imported class 'com.whatever.MyClass'".

The solution was to remove the import statements from fileA.as and FileB.as
and just place one import directly in the .FLA.

(the #include files are on thair way out as well...)

My recomendation: Try to avoid #include, most likely you can get better results by using a static class.

4 comments:

william.bingham said...

Some easy mistakes to make.

1) it's "import" not "#import"
2) import uses the class name, not the filename!

So doing:
import Class1.as;
import Class2.as;

Will conflict since the "as" class has the same name. (Get it)

Should be
import Class1;
import Class2;

And the class name might be case sensitive too. So be careful out there!

Eyal Peleg said...

Hi William,
thanks for the comment. Its nice to know that from time to time someone reads this stuff.

you where of course right about the # being redundent - obviously I did not have it in my code and it was an error in my post (which I now edited out) as for your second comment - you are again right however - I never had an import statement with a filename.

thanks again.

Roger Snowden said...

Okay, that did help.

I guess a simple way of putting it is to say the conflict was the filename extension, ".as". Further, that the .as extension is not needed on an import statement. Presumably on and include as well.

Thanks.

Eyal Peleg said...

Hi Rojer,
as far as I know the .as IS required in include staements.

the problem was that using the import statement in both includes I ended up importing the same class twice (once through each include) and the compiler was not smart enough to handle it.

anyway - I am glad to hear it helped.

 
Clicky Web Analytics