Casting an instance object from an external swf

Hi,

I have a custom class called GoalKeeper.as . In my external swf, i create an instance of this class like

var myGoalKeeper:GoalKeeper = new GoalKeeper()

And the from my main swf, i just make a reference to use myGoalKeeper.

var rootGoalKeeper:GoalKeeper = externalSwf.myGoalKeeper;

And when i run the main swf, i got the following error?
[COLOR=Red]
TypeError: Error #1034: Type Coercion failed: cannot convert game::GoalKeeper@35896381 to game.GoalKeeper.[/COLOR]

myGoalKeeper is just an instance of GoalKeeper class, what is wrong?

Note:I develop classes in Adobe Flex and compile my projects in Adobe Flash CS3.

When you import an swf the main swf doesn’t know about the programming or classes of the imported swf. You will need to cast it instead, and I’m not sure you can even access myGoalKeeper like that. I think you need to do

GoalKeeper(externalswf["myGoalKeeper");]

Sloppy I know, but I’m not sure if you can preserve swf typing on import. If there is a way I’d love to know it.

Thanks Fidodo,
but that didn’t work, got the same error. Because “casting”, called coercion by adobe engineers, is the place where the problem occurs. Flash knows that, i want to reference my instance, it just can not cast it.

Is externalSwf is pointing to the content property of a Loader class? i.e.


var loader:Loader;
var externalSwf:DisplayObject = loader.content;

Also, make sure you are accessing the info after the content is loaded. You can’t access anything until the loader fires an init event.

thanks again,
i gave up to fight Adobe’s Flash bugs and re-coding all my classes and swfs.