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 displayed 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.

Jamie Wong
  • 18,104
  • 8
  • 63
  • 81
  • Possible duplicate: http://stackoverflow.com/questions/2187782/actionscript-3-read-file-text-at-compile-time –  Jul 03 '10 at 01:35
  • @M28 Not duplicate - I have the source that does what I want, but it causes the program to hang for some reason. That post was asking about how to do it in the first place. – Jamie Wong Jul 03 '10 at 02:19
  • In the question you give: `'../../data/map.txt'` and `'../../map.txt'`, which one is correct? –  Jul 03 '10 at 17:50
  • `../../map.txt` is a typo. Thanks – Jamie Wong Jul 03 '10 at 19:10

2 Answers2

8

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

Jamie Wong
  • 18,104
  • 8
  • 63
  • 81
3

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);
  • +1. I think your second parameter is typo, though (as passing the buffer endianess as the enconding doesn't make much sense!). – Juan Pablo Califano Jul 03 '10 at 02:04
  • Thanks for the suggestion on how to actually extract the data - but the program still hangs. – Jamie Wong Jul 03 '10 at 02:13
  • @Juan: At the time of the writing, it was correct, I am not sure if the parameters changed or something. –  Jul 03 '10 at 04:59
  • @Jamie: I think the problem isn't in my code, I am not sure because It is old –  Jul 03 '10 at 05:35
  • @Juan: I just checked, my source code is still working on my old project, even compiled in the newest sdk. –  Jul 03 '10 at 05:39
  • I don't doubt the correctness of your code. I was wondering if anyone had encountered freezes as the result of an embed. With the embed (regardless of using your code or not) it freezes. Without, it does not. This question wasn't about how to accomplish reading in an external file, it was about how to diagnose/fix the freezing problem. – Jamie Wong Jul 03 '10 at 15:58
  • Well, the problem can be with the file permissions, I am not sure, are you using pc or mac? –  Jul 03 '10 at 17:44
  • Using a mac - permissions are 644, which should be fine. `-rw-r--r-- 1 jamiewong staff 41 2 Jul 22:28 map.txt` – Jamie Wong Jul 03 '10 at 19:11
  • Sorry, I use pc, I can't help you with this, but the problem is probably not in the code. –  Jul 03 '10 at 21:21
  • @M28 - Looks like you're probably right - nothing to do with the code. See edit in question - any ideas? – Jamie Wong Jul 05 '10 at 04:45
  • +1 This didn't answer my question, but it is helpful now that it's fixed. Thanks for your help – Jamie Wong Jul 06 '10 at 02:23
  • Create an answer with the content of the answer and mark that as accepted. Also, I use FlashDevelop, I think I would never get that bug. –  Jul 07 '10 at 19:07