artman
artman

Reputation: 63

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).

Upvotes: 4

Views: 2467

Answers (3)

colin moock
colin moock

Reputation: 1188

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/

Upvotes: 14

Markavian
Markavian

Reputation: 84

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();
}

Upvotes: 1

Shvilam
Shvilam

Reputation: 236

As i know it is not possible

Upvotes: -1

Related Questions