Hi all,

I'm working on an API to allow developers to write apps which connect
to an AMFPHP service. For security reasons, we're placing all the
code that actually deals directly with the service in a connector SWF
which sits on our server and is loaded in the developer's app by a
loader class which loads the connector and provides an interface to
it.

An architecture decision has been made to use callback functions to
get messages back to classes in the app, so when the connector
receives messages from the service, it calls callback methods in any
object which has registered itself as a listener (It also dispatches
events like a proper implementation should, but these callbacks are a
legacy hangover from the AS2 version. Y'all know how it is ;) ).

To this end, I've defined two interfaces: IAPIConnector, which defines
the available methods on the single class in the connector SWF, and
IAPIListener, which defines the callbacks which should be present in a
listening class. Classes make calls through a variable in the
connector class cast as IAPIConnector, and the connector calls methods
on objects cast as IAPIListener. This way, neither the loader contains
any imported connector code (just the interface definition) and vice
versa.

This works as expected when both SWF files are on the local
filesystem, but when I attempt to load the Connector from a remote
location, I get errors along these lines:

TypeError: Error #1034: Type Coercion failed: cannot convert
api.test::[EMAIL PROTECTED] to api.interfaces.IAPIListener.
(when passing a listener class [which definitely does implement
IAPIListener] to the loaded connector class )

TypeError: Error #1034: Type Coercion failed: cannot convert
api::[EMAIL PROTECTED] to api.interfaces.IAPIConnector.
(when trying to cast an instance of the loaded connector class to
IAPIConnector [ which it definitely does implement] in the loader
class)

This really has me scratching my head. My best guess is that there's
some kind of ApplicationDomain weirdness going on which is causing
both SWFs to have their own independent definitions of the Interfaces,
and so therefore complaining when something from the other SWF, which
implements its own definition of the interface, is passed through. I
am, however, explicitly using a LoaderContext to load the connector
into a child of the current ApplicationDomain, like so:

$loader = new Loader();
$loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onAPILoaded );
var cxt:LoaderContext = new LoaderContext();
cxt.applicationDomain =new ApplicationDomain( ApplicationDomain.currentDomain )
$loader.load(  new URLRequest( swfUrl ), cxt );

And if that was wrong, surely it wouldn't work locally either? It's
driving me mental!

Any insights very gratefully received,
Henry
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to