开发者

Inject data in an swf at compile time

开发者 https://www.devze.com 2023-01-27 23:30 出处:网络
Is it possible to inject data, for example a collection of assets (video, images...), in an swf at compile time?

Is it possible to inject data, for example a collection of assets (video, images...), in an swf at compile time?

We have a flex application that needs to be able to export an swf at runtime that contains all the necessary data, because it needs to run as a standalone application (on- and offline).

The idea so far was to create a server side script that calls the flex compiler and feed it the data it needs. This approach seems to work fine using the [Embed] tag for single files, but it gets kind of messy when trying to inject collections of data that vary in length for each exported swf.

We could generate an mxml file with one embedded va开发者_高级运维riable for each asset and include it at compile time, but that approach seems for from ideal.

We've looked into some actionscript bytecode libraries, but those do not seem to be fit for this.

Any suggestions or other approaches for this kind of problem?

Thx,

Bert


[Embed] is definitely the way to go. You can generate an AS file that has lots of embeds. While the generated code might be a bit ugly, you can generate a nicer api too. For example, if you want an array, generate code like this:

[Embed(...)]
private var img_0:Class;

[Embed(...)]
private var img_1:Class;

[Embed(...)]
private var img_2:Class;

public var images:Array = [img_0, img_1, img_2];

That way the only ugliness is in private variables only the code generator will see. The public variable is an array.


I'm not sure why you need to do that but i guess i'll try to generate the needed actionscript file from template or something like that and then call the flex compiler. Hope this helps you...


try as3swf
it is able to generate an swf file from an empty ByteArrayand afaik it's possible to insert embedded graphics there


Like Sam said, [Embed] could work, but what are you trying to load? My first reaction is that recompiling for every request would be a big drag on the server.

0

精彩评论

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