AS3,以SWF作为自定义类型加载 [英] AS3, loading in a SWF as a custom type
问题描述
这里有基本问题。通常在AS3中,你通过Loader加载到SWF中,你得到的是一些类型为Loader的伪MovieClip。
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".
在sun下将这个加载的SWF转换为扩展MovieClip而不是Loader的自定义类型,假设SWF是使用自定义类型的基类发布的?没有数据丢失?
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?
或者,你不能,你甚至可以从一个自定义类型扩展Loader本身?
Alternatively, let's say you can't, can you even cast it from a custom type that extends Loader itself?
推荐答案
您可以这样做:
stub swf中的代码:
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;
}
}
。
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");
}
这篇关于AS3,以SWF作为自定义类型加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!