Copy link to clipboard
Copied
Hi,
I am a neewby with Animate.
What I want:
A button that changes position based on y numbers pulled from a JSON file.
So for example: on frame 1 the y = 200, on frame 2 the y = 202, on frame 3 the y = 206, etc.
I know how to do this on just one frame:
// load JSON file
var req = new XMLHttpRequest();
req.open("GET", "test.js", true);
req.addEventListener("load", transferComplete.bind(this));
req.send();
//outputJSONfile
function transferComplete(e){
var JSONObject = JSON.parse(req.responseText);
console.log(JSONObject["y"]);
var verticaal = JSONObject["y"];
this.btn.y = verticaal;
}
And my JSON file:
{
"y" : 200
}
But how do I do the same for a JSON file with lets say a 100 different numbers and a 100 frames.
Hopefully someone can help me out!
Hi.
When you store a value in Animate CC using the var keyword, that variable is available to that frame only. If you want to keep your loaded and parsed JSON data available for the entire timeline, set this JSON data as a property of the main timeline.
Something like this:
function transferComplete(e)
{
exportRoot.json = JSON.parse(req.responseText); // exportRoot is a global reference to the main timeline created by Animate CC
}
Then, from anywhere, you can just say:
this.mc.y = exportRoot.json["
...
Copy link to clipboard
Copied
Hi.
When you store a value in Animate CC using the var keyword, that variable is available to that frame only. If you want to keep your loaded and parsed JSON data available for the entire timeline, set this JSON data as a property of the main timeline.
Something like this:
function transferComplete(e)
{
exportRoot.json = JSON.parse(req.responseText); // exportRoot is a global reference to the main timeline created by Animate CC
}
Then, from anywhere, you can just say:
this.mc.y = exportRoot.json["y"];
I hope this helps.
Regards,
JC