Importing an SWF file in Actionscript 3
I have an external SWF file that I need to load at runtime. However, contained inside the SWF is a single MovieClip - in fact, it is a custom class that extends MovieCl开发者_如何转开发ip. This custom class has its own instance variables and methods. So, there is an AS class that this MovieClip is linked to.
However, when I load the SWF file in the normal way (i.e. with Loader and URLRequest), I cannot access the methods and variables of my custom class. Flash just thinks that it is of type MovieClip, and I have no access to the properties of my custom class.
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. Then you code would be:
loadedMC.getChildAt(0) as IYourCustomClass
-- this provides access to all the methods and getters/setters.
精彩评论