Every time I need to embed an image, text or binary file in ActionScript I have to go google “actionscript embed text file” because I simply don’t know this code snippet by heart:
[Embed(source="text.txt",mimeType="application/octet-stream")]
private var TextClass:Class;
I bet this site gets a ton of visits from people like me.
I just don’t know why but I can’t remember this [Embed] construct. I even have several snippets app helpers installed on my mac but all the time it’s faster to google “actionscript embed text file” instead of launching some app.
Same thing is with HTML CDATA syntax. I just can’t remember it. Every time I google “CDATA” just to get this:
<![CDATA[
...
]]>
I heard on Russian twitter that flash decompilers fail to parse embeded binary data (for example another SWFs). Tested it locally and that rendered to be true — the content of embeded SWF was impossible to extract. That seemed so simple yet effective. Just use something like
[Embed(source="swf.swf", mimeType="application/octet-stream")]
Someone could write a simple command line script to split SWFs into several parts to embed them inside a loader SWF and assemble again. Or it’s possible to add simple encryption to go further.
This idea is indeed very simple so someone might have made a tool like this already. I didn’t find a tool but I did find a post about this technique. And since then I successfully used it in one of my projects.
Separating graphical/sound assets and actual logic is a very good practice. It allows to avoid a lot of problems. For some time I’ve been using compiled SWFs with ActionScript skin classes embeding symbols from that SWF using [Embed] meta tag. But recently I came across much better solution using SWC.
So the algorithm is the following:
- Create a new AS project in Flex Builder.
- Create a new FLA at ‘assets/assets.fla’.
- In Publish Settings of that FLA set ‘Export SWC’ checkbox.
- Create and export assets via ‘linkage properties’ as something like ‘assets.MySymbol’.
- Publish SWC.
- In Flex Builder add this SWC at Project -> Properties-> ActionScript Build Path -> Library Path -> Add SWC.
- Now in Flex Builder we can import and use assets.MySymbol and IDE knows about it and its type.
Recent Comments