Why?
TLDR; the project JSON string is embedded at compilation-time for easier usage. So, if you edit your levels afterward, the embedded levels won’t automatically update, unless you recompile your code.
Explanation: you simply need to realize that the project.json
parsing occurs at 2 distinct moments:
- at compilation time, the JSON is parsed and its content is used to build the data structure and strict-typing for your code. For example, all the are transformed into actual fields of the
all_levels
field in your project instance. - at runtime, the JSON is parsed for its actual content, and the typed structure is populated with values. By default, the last JSON content used for compilation is also re-used to initialize your project instance.
Loading project JSON at runtime
You have 2 easy ways to parse an updated JSON project file at runtime.
1. Using the constructor optional parameter
var jsonContent : String = WhateverFileApiYouUse.readFile("myProject.json");
var p = new MyProject( jsonString ); // will override embedded JSON
2. Calling parseJson()
The parseJson()
method dynamically updates a project instance values:
function onMyProjectFileChangeOnDisk(newJsonFileContent:String) {
p.parseJson( newJsonFileContent );
}