as3 blog

thoughts on actionscript 3 development

   Nov 02

embeding json, xml and text files

you could load some json data at runtime and most of the time this is the best thing to do as it’s likely you’ll want to be able to change that data without recompiling. but what about some json data for a sprite sheet? it’s easy enough to embed images in actionscript but what about text files? it’s a little bit different..

package
{
  public class EmbedJsonTest extends Sprite
  {
    [Embed(source="data.json",mimeType="application/octet-stream")]
    private const JsonData : Class;

    public function EmbedJsonTest()
    {
      var ba : ByteArray = new JsonData() as ByteArray;

      trace("JsonData = " + ba.readUTFBytes(ba.length));
    }
  }
}
									

You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Reply

Your email address will not be published. Required fields are marked *

* 6+3=?

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>