Fundamental question here. Typically in AS3 you load in a SWF via the Loader, and what you get is some sort of pseudo MovieClip that is of type "Loader".
Is there any holy way under the sun to cast this loaded SWF to a custom type that extends MovieClip and not Loader, assuming the SWF was published with a base class of the custom type? Without data loss?
Alternatively, let's say you can't, can you even cast it from a custom type that extends Loader itself?
You can do something like this:
Code in the stub swf:
package {
import flash.display.MovieClip;
public class Stub extends MovieClip implements IStub {
public function Stub() {
trace("Stub::ctor");
}
public function traceIt(value:String):void {
trace("Stub::traceIt " + value);
}
}
}
I'm using an interface, but it's not strictly neccesary.
package {
public interface IStub {
function traceIt(value:String):void;
}
}
Code in the "main" swf.
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT,handleInit);
loader.load(new URLRequest("Stub.swf"));
function handleInit(e:Event):void {
var stub:Stub = loader.content as Stub;
// or, using an interface
// var stub:IStub = loader.content as IStub;
stub.traceIt("testing");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With