简体   繁体   English

在Actionscript 3中导入SWF文件

[英]Importing an SWF file in Actionscript 3

I have an external SWF file that I need to load at runtime. 我有一个外部SWF文件,需要在运行时加载。 However, contained inside the SWF is a single MovieClip - in fact, it is a custom class that extends MovieClip. 但是,SWF中包含的是单个MovieClip-实际上,它是扩展MovieClip的自定义类。 This custom class has its own instance variables and methods. 该自定义类具有自己的实例变量和方法。 So, there is an AS class that this MovieClip is linked to. 因此,有一个MovieClip链接到的AS类。

However, when I load the SWF file in the normal way (ie with Loader and URLRequest), I cannot access the methods and variables of my custom class. 但是,当我以常规方式(即通过Loader和URLRequest)加载SWF文件时,无法访问自定义类的方法和变量。 Flash just thinks that it is of type MovieClip, and I have no access to the properties of my custom class. Flash只是认为它是MovieClip类型,因此我无法访问自定义类的属性。

All that remains is the graphics inside the movie clip. 剩下的就是影片剪辑中的图形。

Does anyone know what's going on here? 有人知道这是怎么回事吗?

try casting it: 尝试投射:

loadedMC.getChildAt(0) as YourCustomClass

You can even set up an interface, say IYourCustomClass , which can be implemented by YourCustomClass and import the interface in you main movie, to save some bytes. 您甚至可以设置一个接口,例如IYourCustomClass ,该接口可以由YourCustomClass实现,并将该接口导入您的主影片中,以节省一些字节。 Then you code would be: 那么您的代码将是:

loadedMC.getChildAt(0) as IYourCustomClass -- this provides access to all the methods and getters/setters. loadedMC.getChildAt(0) as IYourCustomClass -这提供了对所有方法和getter / setter方法的访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM