views:

517

answers:

2

I have a parent SWF file that defines a Widget base class.

I then load an external SWF into the parent. The external SWF's document class derives from the Widget base class -- let's call it DerivedWidget for example.

The problem is that when I load the external SWF, I cannot cast the Loader.content (shows in debugger as having the DerivedWidget type) to the Widget type. I use the "as" operator to cast the content as a Widget in the parent SWF once the load completes, but the cast results in "null".

This behavior is not expected, because the external SWF is loaded into the parent's application domain, and the Loader's content shows up in the debugger as DerivedWidget, which I know derives from Widget, but the cast to the base Widget class is failing.

Can anyone explain this unexpected behavior and offer a solution?

[Edit: looking back at an earlier code snapshot... this was working before, but now it isn't... and the loading and casting code hasn't changed]

[Edit2: actually, it seems to be failing when debugging in the Flash IDE. When run normally, everything loads into the correct ApplicationDomain (sameDomain=true); this is obviously a huge bug]

A: 

There are some bugs in the way that DocumentClass does inheritance.

http://bugs.adobe.com/jira/browse/FP-2999 (need to log in to adobe's bug tracker)

My recommendation is to take it off the stage and export it through the library instead, it will work from there. In fact my rule of thumb is "never use document classes."

Nate Austin
I gave up on loading anything external into Flash. Flash Player 9 is useless for loading external AS3 content, because it's impossible to unload it, especially for something like an Adobe Captivate animation. The memory usage increases incrementally as content is reloaded. The event dispatching API sucks, prevents GC, and won't allow me to examine arbitrary existing events and function references. The schools we work with re-image their computers only once a year, so thousands of users are stuck with Flash Player 9. I cannot justify paying for this software; it doesn't work as advertised.
Triynko
A: 

I have experienced the similar problem. The solution are two fold.

  1. Use DerivedWidget(mc), instead of mc as DerivedWidget. There are some articles addressing this problem, you need to find it out.

  2. make sure the class DerivedWidget is accessible in both compilation environment. If you use Module or invovle different Flash domain, be more careful.

Juguang