AS3,加载在SWF为自定义类型 [英] AS3, loading in a SWF as a custom type

查看:145
本文介绍了AS3,加载在SWF为自定义类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里根本的问题。通常,在AS3您在SWF通过加载器加载,而你得到的是假的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".

有没有在阳光下的圣洁的方式来施放此加载的SWF到扩展影片剪辑,而不是装载机,假设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?

另外,让我们说你不能,你能甚至扩展装载机本身?自定义类型强制转换

Alternatively, let's say you can't, can you even cast it from a custom type that extends Loader itself?

推荐答案

您可以做这样的事情:

code存根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);
    	}
    }
}

我使用一个接口,但它不是严格neccesary。

I'm using an interface, but it's not strictly neccesary.

package {

    public interface IStub {

    	function traceIt(value:String):void;

    }
}

code。在主SWF。

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");
}

这篇关于AS3,加载在SWF为自定义类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆