Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all definitions in an ApplicationDomain of a loaded SWF?

When you load a SWF into another, the loader SWF can get specific definitions from the loaded SWF using ApplicationDomain.getDefinition(name:String). For example:

package 
{
    // ... imports

    public class SWFLoader extends Sprite
    {
        private var loadedAppDomain:ApplicationDomain;

        public function SWFLoader()
        {
            var request:URLRequest = new URLRequest("test.swf");
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onTestLoadComplete);
            loader.load(request);
        }

        private function onTestLoadComplete(event:Event):void
        {
            var loaderInfo:LoaderInfo = LoaderInfo(event.target);
            loadedAppDomain = loaderInfo.applicationDomain;

            // Here we can get ANY defined symbol (class, namespace or function according to Adobe Flash help)
            var someSymbolClass:Class = Class(loadedAppDomain.getDefinition("SomeSymbol"));
            var someSymbolSprite:Sprite = Sprite(new someSymbolClass());

            addChild(sprite);
        }
    }
}

How can I get all of the definitions in a SWF, without specifying each explicitly?

like image 280
Lucas Gabriel Sánchez Avatar asked Nov 10 '10 12:11

Lucas Gabriel Sánchez


2 Answers

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

See the official documentation for the method and this blog post about the Flash Player release.

like image 199
Mark Avatar answered Sep 21 '22 09:09

Mark


EDIT: This is the quickest solution to your problem : http://www.bytearray.org/?p=175

Hi, you could use this library : https://github.com/claus/as3swf/wiki/ Don't have the time to do deeper test, but here is what i found :

1 - I have created a .swf containing in the library 2 exported MC, $Test and $Test2 2 - Once the .swf loaded by a Loader, i run this code :

var swf : SWF = new SWF(loader.contentLoaderInfo.bytes);
trace(swf);

3 - In the output you'll notice theses lines :

[76:SymbolClass] 
  Symbols:
    [0] TagID: 2, Name: $Test2
    [1] TagID: 1, Name: $Test

I think that there is a way to obtain this info directly thru the library API

like image 21
OXMO456 Avatar answered Sep 17 '22 09:09

OXMO456