Flash 10 Attaching a png file from an external swf compiled with swfmill

136 views Asked by At

I wish to load an external swf compiled with swfmill, at run time. In other words, loading it asynchronously (not compiled together with the file). This swf contains 2 assets: file1.png and file2.png.

It's mostly working, except for this problem: how to attach the resources in the file? Normally I would use attach()…

var _urlLoader = new URLLoader();
var _urlRequest = new URLRequest("libgfx.swf");
_urlLoader.load(_urlRequest);
_urlLoader.addEventListener(Event.COMPLETE, onComplete);

public function onComplete(e:Event) {
    trace("Received shared libgfx.swf. Length: " + _urlLoader.data.length);  // displaying the size correctly

    var displayObjectLoader:Loader = new Loader();
    displayObjectLoader.load(_urlRequest);
    var displayObject:DisplayObject = addChild(displayObjectLoader);

    // How would you attach file1.png or file2.png?
    // …?
}

Any help appreciated :)

1

There are 1 answers

0
Tamas Gronas On BEST ANSWER
  • Convert the assets to MovieClip.
  • Add Linkage for them.
  • Use the following code to load it:

    var context:LoaderContext       = new LoaderContext( );
        context.applicationDomain   = ApplicationDomain.currentDomain;
    
    var loader : Loader = new Loader( );
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete );
        loader.load( new URLRequest( "assets.swf" ), context );
    
        function complete ( e:Event ) : void
        {
            var Asset : Class = e.target.applicationDomain.getDefinition("the linkage of the asset") as Class;
            var asset : MovieClip = new Asset( );
            addChild( asset );
        }
    

Hope this helps.

Cheers

Tamas Gronas