Reputation: 1150
I am loading an external SWF containing uninstantiated MovieClip Symbols. I can get the SWF loaded, no problem. If I call:
loader.contentLoaderInfo.applicationDomain.getDefinition( "TestClip" ) as Class
I get the class of a Library symbol called "TestClip", which I can then instantiate. Jawesome.
The issue I'm having is that basically I want to have access to all of the Library symbols without needing to explicitly know their names. I was hoping to use:
describeType( loader.contentLoaderInfo.applicationDomain );
...to get reflective access to the Library symbols, but the XML returned doesn't seem to include any references to them. Perhaps I'm calling it on the wrong object? I also don't want to have to explicitly create coded instances to gain access. This is for a tool for Flash artists, and it's important to avoid code, even simple code.
There must be someway to get access to the symbols. Any suggestions on how to accomplish this would be appreciated!
Related:
as3 - getting library symbols from an Assets class
AS3 - getting symbols from an assets library WITHOUT Flex
Flash AS3 : addChild() does not display imported movieclip
Upvotes: 0
Views: 3295
Reputation: 1150
http://www.bytearray.org/?p=175
http://etcs.ru/pre/getDefinitionNamesSource/
Both of those classes seem to accomplish what I'm looking to do by analyzing the raw ByteArray data of the SWF. I'm submitting these as the best answer for now, but as native way to accomplish this is still desired. That will get the answer if someone can show such a method here.
A quick rundown on the usage of the second class, getDefinitionNamesSource, as it's a bit simpler to implement.
import ru.etcs.utils.getDefinitionNames;
Of course, import the class.
var classes : Array = getDefinitionNames( displayObject.loaderInfo.bytes );
Then you can call the above where displayObject is any instantiated DisplayObject
, passing it either the loaderInfo
or the loaderInfo.bytes
( the class will get the bytes from the loaderInfo, if that's what you pass it ). It returns an array of the class names. The nice thing about this class is that it returns unlinked classes! This makes it ideal for this purpose! You can then use getDefinition() on the loaded SWF to get the Class such that you can instantiate it! In the following example. A SWF with MovieClip
symbols is loaded. In the Event.COMPLETE handler, the following code will instantiate one of those symbols as myInstance, at which point, you can do whatever you want.
var MyAsset : Class = loader.contentLoaderInfo.applicationDomain.getDefinition( classes[0] ) as Class;
var myInstance : MovieClip = new MyAsset();
Upvotes: 1