Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed a JSON file in an SWF

Can I use include in actionscript in some form?

var somevar = include "file.json";

Where "file.json" contains JSON data

like image 428
Somewater Avatar asked Dec 11 '22 15:12

Somewater


2 Answers

It's not this simple, but possible. First, you have to embed a JSON file as is:

[Embed(source = 'file.json', mimeType='application/octet-stream')]
private static const YourJSON:Class;

Then, to get whatever is embedded (a String, a Bitmap, an SWF), you need to instantiate a variable with this type.

var somevar:String=new YourJSON();

Then you need to parse the JSON, the correct syntax for this varies by JSON and parsing library (this part is mainly determined by your Flash player target). RafH's answer has a syntax for an array and (IIRC) FP10 compatible library.

like image 176
Vesper Avatar answered Dec 14 '22 03:12

Vesper


Also may want use ASC 2.0. (from here) New syntax allows you to use:

var h:Object = include 'conf.json'; // where conf.json contains correct JSON
like image 41
Somewater Avatar answered Dec 14 '22 03:12

Somewater