Type coercion to the same type fails

Hi,
I am having a weird casting problem: I am receiving this error

TypeError: Error #1034: Type Coercion failed: cannot convert shared.plugins.toolbar2.toolbar::Globalization@18f84d9 to shared.plugins.toolbar2.toolbar.Globalization.

The getter function is this one

private function get localeFormatter(): Globalization {

trace("commons.getItem(\"localeFormatterTB\") = " + commons.getItem("localeFormatterTB"));
trace("commons.getItem(\"localeFormatterTB\") is Globalization -> " + (commons.getItem("localeFormatterTB") is Globalization));
trace(flash.utils.getQualifiedClassName(commons.getItem("localeFormatterTB")));
trace(flash.utils.getQualifiedClassName(Globalization));

		return commons.getItem("localeFormatterTB");
}

Trace returns the following lines

commons.getItem("localeFormatterTB") = [object Globalization]
commons.getItem("localeFormatterTB") is Globalization -> false
shared.plugins.toolbar2.toolbar::Globalization
shared.plugins.toolbar2.toolbar::Globalization
TypeError: Error #1034: ...

The error is triggered when trying to return the value, that should be cast to Globalization, but it looks like it already is of type Globalization, so why there should be a casting problem? It is really weird to see that “is Globalization” returns false, even if it is evident by the following trace that it IS.

I don’t think it is in some way related to application domain or similar, because Globalization class is always the same through all swfs using it (just another one).

Another weird detail is that this function works correctly for the same game if put in a different folder (domain).

Any idea?

Its related to application domain or similar.

You can have the same exact class in different SWFs and if they’re in different application domains then they’ll be separate class definitions. You can recognize this with the @####### suffix indicating a different address location for the other class (I actually don’t remember if it actually relates to an address, but might as well think of it that way). This classes will act the same, have the same names, but will not be equal and instances of each will not be compatible with types of the other.

If you want compatibility, you need all instances to reference the same definition from the same source (domain)

Well, all the involved SWFs use the same domain, the standard one (ApplicationDomain.currentDomain).
And how comes everything works in one domain and not the other one? The SWFs are the same, not even recompiled.
A fast fix is using a generic type “*” instead of “Globalization” as the return item, but it does not satisfy me.

If you’re serving SWFs from different domains, then they’ll be in different security domains and inherently incompatible.

More info: http://www.senocular.com/flash/tutorials/contentdomains/