AS3 & Swfmill: How to access assets in swfmill-generated library swf

1.6k views Asked by At

I'm creating library swfs in as3 this way, works like a charm (except for the slow mxmlc compiler):

package {
 import flash.display.Sprite; 
 public class Library extends Sprite {
   [Embed(source="assets/test.png")]
      public var TestBitmap:Class; 
 }
}

I would like to create the same kind of libary using swfmill. I've tried the following swmfill simple xml:

<movie version="10">

Examining the libraries in FlashDeveloper's explorer reveals that the as3 library exports BOTH classes and symbols, but the swfmill library exports ONLY symbols. My host application is accessing the as3 library assets this way:

private var loader:Loader = new Loader();

private function onCreationComplete():void {
    this.loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
}

private function onComplete(e:Event):void {
    var resourceClass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("Library") as Class;
    var resources:Object=new resourceClass();
    var testBitmapClass:Class = resources['TestBitmap'] as Class;   
    var testBitmap:Bitmap = new testPngClass();
    this.addChild(testBitmap);
}

But with no exported swfmill classes, there's obviously nothing to instatiate...

Is swfmill expected to export classes this way? If not, is there a way of accessing the symbols without instantiating them as classes?

Jonas

1

There are 1 answers

1
Don-Duong Quach On BEST ANSWER

In short, no. I've been looking into this as well. Since I work with the Flash IDE, Haxe, and flex I'll outline the different methods for accessing content by embedding it in a swf.

It doesn't look like there's a way to directly instantiate a symbol. If your assets were exported by the Flash IDE, normally you would set the properties to export for Actionscript to get at the symbol. In Haxe you'd specify a class to match that in the swfmill xml. With flex you'd define a class and use the Embed metadata tag to access the symbol by embedding the swf. http://livedocs.adobe.com/flex/3/html/help.html?content=embed_4.html

This script which might be helpful to you for generating the export classes. http://wiki.disemia.com/HaXe_SWFMILL_Resource_Converter

If you're using AS3, you'll probably have to use mxmlc anyway if you're compiling your project from the command line. Since speed is the issue for you, you should consider using fcsh.