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 _urlReque开发者_运维百科st = 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 :)
- 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
精彩评论