Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to get values from JSON on every single frame

Explorer ,
Feb 06, 2019 Feb 06, 2019

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!

265
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 06, 2019 Feb 06, 2019

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["
...
Translate
Community Expert ,
Feb 06, 2019 Feb 06, 2019
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines