External Config file in Actionscript 3
I need to be able to load external configuration files into my flex app. I've read that this is possible using embeds, so long as the mimeType is set to application/octet-stream.
package learning {
import org.flixel.*;
public class PlayState extends FlxState {
[Embed(source = "../../data/tiles.png")] private var _tiles:Class;
[Embed(source = '../../data/map.txt', mimeType = "application/octet-stream")] private var ExternalMapData:Class;
public var txt:FlxText;
public var player:FlxSprite;
override public function create():void {
bgColor = 0xffaaaaaa;
super.create();
}
override public function update():void {
super.update();
}
}
}
When I compile this using mxmlc
, it compiles successfully with no errors. When I run the SWF, it loads all the Flixel menus then hangs.
If I comment out the [Embed(source = '../../data/map.txt'
line, it compiles and doesn't hang.
Why is this embed causing a freeze?
Version info for mxmlc:
Adobe Flex Compiler (mxmlc)
Version 4.0.0 build 14159
EDIT
It turns out errors weren't being dis开发者_JS百科played properly, but this is what I'm getting from attempting the embed:
VerifyError: Error #1014: Class mx.core::ByteArrayAsset could not be found.
Google turns up a bunch of people with the same problem, but no apparent solution.
import mx.core.ByteArrayAsset; ByteArrayAsset
doesn't help either.
Aha! It turns out the solution was very simple - runtime shared libraries weren't being statically linked into the swf, and the path wasn't being set properly for access during runtime. The solution is simple:
Either modify flex-config to say
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
or manually pass in the parameter to mxmlc
mxmlc -static-link-runtime-shared-libraries=true -debug=true Main.swf -- Main.as
I'll answer this one with my answer to another question:
[Embed(source = "ExampleText.txt", mimeType = "application/octet-stream")]
protected var AAAAAA:Class;
var tmp:ByteArray = new AAAAAA();
var result:String = tmp.readMultiByte(tmp.bytesAvailable, tmp.endian);
精彩评论