Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all classes contained within an SWF

Is there a way to get a list of all classes contained within then currently running SWF? You could use describeType on the root and then traverse down the list to find all Classes of instances referenced within your app, but this method does not work for classes that have been included, but not referenced (local references, for example).

like image 284
artman Avatar asked Dec 10 '22 21:12

artman


2 Answers

as of Flash Player 11.3, you can use ApplicationDomain.getQualifiedDefinitionNames().

basic example:

var definitions:Vector.<String> = this.loaderInfo.applicationDomain.getQualifiedDefinitionNames();

the following code demonstrates how to list all definitions (including classes) for a .swf file in Flash Player 11.3, with a failure message in older versions of Flash Player:

var t:TextField;
t = new TextField();
t.width = 1200;
t.height = 700
t.border = true;
t.background = true;
t.text = "Definition List\n";
t.appendText("========================================\n");
var definitions:*;
if (this.loaderInfo.applicationDomain.hasOwnProperty("getQualifiedDefinitionNames")) {
  definitions = this.loaderInfo.applicationDomain["getQualifiedDefinitionNames"]();
  for (var i:int = 0; i < definitions.length; i++) {
    t.appendText(definitions[i] + "\n");
    t.scrollV = t.maxScrollV;
  }
} else {
  t.appendText("Could not read classes. For a class list, open this .swf "
               + "file in Flash Player 11.3 or higher. Your current "
               + "Flash Player version is: " + Capabilities.version);
}
addChild(t);

For a list of classes in Flash Player 11.2 and older, you must read the bytes of the .swf and parse the class names manually. here are two well-known libraries that demonstrate:

Thibault Imbert's SWFExplorer

http://www.bytearray.org/?p=175

Denis Kolyako's getDefinitionNames()

http://etcs.ru/blog/as3/getdefinitionnames/

http://etcs.ru/pre/getDefinitionNamesSource/

like image 124
colin moock Avatar answered Feb 02 '23 20:02

colin moock


An alternative maybe:

In the first frame of the embedded SWF, set a property listing all the classes you want to make available.

e.g.:

this.availableClasses = ["MainMenuClass", "SmileyFaceClass", "JumpButtonClass"];

Then, on load:

var classes:Array = loader.content.availableClasses;
var domain:ApplicationDomain = loader.loaderInfo.applicationDomain;
var classType:Class;
var clip:*;
for each(var className:String in classes) {
  classType = domain.getDefinition(className);
  clip = new classType();
}
like image 23
Markavian Avatar answered Feb 02 '23 19:02

Markavian