开发者

"Link" against a SWC in Flex

I'm trying to do a very simple app in Flash/Flex, that loads an image embedded in the swf itself and then shows it. The thing is I'm trying to do it using the command line only (mxmlc and compc) and without using @Embed, and failing miserably.

I have a very simple Main.as :

package
{
 开发者_C百科   import flash.display.*;
    import flash.utils.*;

    public class Main extends Sprite
    {
        public function Main () : void 
        {
            var pDef:Class = getDefinitionByName("icon_big.png") as Class;
            var _image:BitmapData = new pDef(0, 0);

            var pSprite:Sprite = new Sprite();          
            pSprite.graphics.beginBitmapFill(_image);
            pSprite.graphics.drawRect(0, 0, _image.width, _image.height);
            pSprite.graphics.endFill();

            addChild(pSprite);
        }   
    }
}

This works fine if I add icon_big.png to the Library using the Flash IDE, but I can't figure out how to do it from the command line.

I'm using compc to put the png inside a swc :

compc --include-file icon_big.png icon_big.png -output assets.swc

This generates a 17 kb assets.swf, slightly bigger than icon_big.png. Then I try to compile and link Main.as :

mxmlc -include-libraries+=assets.swc Main.as

This produces a 944 byte Main.swf, which clearly doesn't include the asset, and fails at runtime.

According to the mxmlc docs I found, -include-libraries should link with every class, including the ones not directly referenced by code (as is the case here, since I'm getting the class from code), and it unsurprisingly fails at runtime.

Note that this same code (or, more precisely, quite equivalent code) works when used within a Flash project - I'm not looking to fix the code, but how to do in the command line whatever Flash does internally.

I feel I'm just "not getting" something... any clues?


I recommend you to download the swftools from swftools.org. Once you have them, run:

    swfdump -D assets.swf

Take a look in particular at the output which relates to SWF tag with value 76 (0x4C), called SYMBOLCLASS.

Here is an example of an exported class, named IntegerMemberBySlot:

[04c]        24 SYMBOLCLASS
                    exports 0001 as "IntegerMemberBySlot"

What symbols are you exporting from your assets.swf?


Have you tried adding the path of the assets to your source path parameter when compiling with mxmlc?

-source-path ./PATH/TO/ASSET


I think you need to embed the PNGs in a class, then compile that class into a SWC. I don't think you can put the PNGs directly into a SWC like you are trying to, but I could be wrong.


I had a similar situation (large project, resource swc with graphic assets), and no matter what I tried, I could't get Flex to include assets and classes not directly referenced from the project (I wanted to include different skins, and then instantiate the proper one at runtime, depending on the configuration).

Finally, I found a workaround by instead of static swc liking, switching over to runtime shared libraries (RSLs). Basically, flex unbundles the swc, and loads and links the included swf in runtime, before running the application itself. All of the classes and assets in the swf are loaded this way. May not be exactly what you're after, but it works for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜