Reputation: 5434
Is there a way to access all exported symbols in a *.swf file?
I mean all the symbols that are marked Export to Actionscript in the Library of Flash IDE. That way I could use getDefinition() class without having to know the name of the symbol beforehand.
This is for an internal tool made in AS3 that will work along a framework, which needs to perform some operations on every symbol of a *.swf file.
So performance isn't required, and a hackish solution (accessing ByteArray of the swf or something like that) is valid.
Thanks
As Daniel suggested, I ended up using as3swf to parse the ByteCode of the *.swf file and read the class.
Here's a simple function I made that returns an array containing the symbol names, ready to be used with getDefinition(). You must pass in a ByteArray of the *.swf file.
private function getSymbolList(bytes:ByteArray):Array {
var swf:SWF = new SWF(bytes);
var ret:Array = [];
for each(var tag:ITag in swf.tags) {
if(tag is TagSymbolClass) {
var symbolClass:TagSymbolClass = tag as TagSymbolClass;
for (var i:int = 0; i < symbolClass.symbols.length; i++) {
ret.push(symbolClass.symbols[i].name);
} return ret;
}
} return ret;
}
With the new 11.3 Flash API, this feature is built-in.
var definitions:Vector.<String> =
this.loaderInfo.applicationDomain.getQualifiedDefinitionNames();
Upvotes: 1
Views: 1035
Reputation: 35684
It is possible by reading the bytecode of the swf, de-serializing it and reading the class names.
This is complicated work though, so it's best to look to low level libraries that already do that. the as3commons bytecode class does this.
http://www.google.com/codesearch#Ueq88nAe-j0/trunk/as3-commons-bytecode/
as3swf can also get at this data. you can have a look through the classes and see how they do it, or just use the classes.
I haven't actually used them, so I don't have any code to share, but hope this helps.
Upvotes: 3