Highlighted

How to get values from JSON on every single frame

Explorer ,
Feb 06, 2019

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!

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

TOPICS
Discussions

Views

66

Likes

Translate

Translate

Report

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

How to get values from JSON on every single frame

Explorer ,
Feb 06, 2019

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!

Adobe Community Professional
Correct answer by JoãoCésar | Adobe Community Professional

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

TOPICS
Discussions

Views

67

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 06, 2019 0
Adobe Community Professional ,
Feb 06, 2019

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

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 06, 2019 0