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

Reading JSON Atlas into Animate (branched from: Assigning XML content to dynamic text fields)

Community Beginner ,
Apr 14, 2018 Apr 14, 2018

Copy link to clipboard

Copied

Hello

I try to load json atas into animate cc but didn't succeed to do it right now. I read you've got a working example.. Can you provide it to me please?

Thanks a lot !!

Views

4.9K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 17, 2018 Apr 17, 2018

Hi.

Do you want to simply load a JSON file using Animate CC and HTML5 (Canvas)?

Votes

Translate

Translate
LEGEND ,
Apr 14, 2018 Apr 14, 2018

Copy link to clipboard

Copied

There is a big difference between importing XML to go into textfields, and reading JSON as part of a texture atlas. So I made your question be its own post. Hopefully you'll get some answers.

You could describe in more detail what you're trying to do.

Votes

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
community guidelines
Community Beginner ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Ok thanks.

Votes

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
community guidelines
Community Beginner ,
Apr 15, 2018 Apr 15, 2018

Copy link to clipboard

Copied

what do you want for as3 or canvas or like component for what air

before load main content you can import everything to insite after canvas created  limited but you can change atlas depending situation

what do you want to do and why you want to do explain please very simple what is your target if i unerstand i can help you

Votes

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
community guidelines
Community Beginner ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

All with HTML5. In fact I had a great working example of what I want to do but it's made in Edge animate not animate cc.. If you want I can send you the Edge animate example so you will be able to see if it's possible to do that in Animate CC ?

Votes

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
community guidelines
Explorer ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

I'm looking for the same thing I think Chris.. if ever you get an answer, tell me

Thanks !

Votes

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
community guidelines
LEGEND ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Votes

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
community guidelines
Community Beginner ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Thank you for the link but it doesn' explain how to do it in Animate CC

Votes

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
community guidelines
LEGEND ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/Chris+Lhaut  wrote

Thank you for the link but it doesn' explain how to do it in Animate CC

Yes, it does. It explains how to do it in JavaScript. The scripting language in HTML5 Canvas documents is JavaScript. The code in Animate to load and parse a JSON file would be literally identical.

Votes

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
community guidelines
Community Expert ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Hi.

Do you want to simply load a JSON file using Animate CC and HTML5 (Canvas)?

Votes

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
community guidelines
Community Beginner ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Yes I want to load all the informations from the json file and display it in Animate CC

Votes

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
community guidelines
LEGEND ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Anything JavaScript can do can be done in Animate too. Here's an article on parsing JSON text into a object variable:

JSON.parse()

Here's a quick test that works in Animate:

var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');

alert(obj.age);

Message 4 in this discussion shows how the text file itself can be read in. It is using an xml file as an example, but it could be any text file:

Assigning XML content to dynamic text fields

Votes

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
community guidelines
Community Beginner ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Thanks for the informations! And what about displaying an image ? if for example there is a field like "test.jpg" in my json file to display in Animate CC ?

Votes

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
community guidelines
LEGEND ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

See kglad's 'Correct' answer in this discussion:

HTML5 Canvas - import images at runtime

Votes

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
community guidelines
LEGEND ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

https://forums.adobe.com/people/Colin+Holgate  wrote

See kglad's 'Correct' answer in this discussion:

HTML5 Canvas - import images at runtime 

Err, that thread explains how to load and display bitmaps. Not how to load and parse JSON files.

Votes

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
community guidelines
Community Beginner ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Thanks !

Votes

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
community guidelines
LEGEND ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

I was answering message number 12.

Votes

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
community guidelines
Community Beginner ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

There's an error in my original post guys, sorry. What I'm looking for is to connect JSON datas to Animate CC like we did in the past with Flash and XML.

So I mean I have different fields in a json file and in Animate CC I need a loop that displays all the informations in my json file (for example a date, a text or something else.

Do you understand ?

Thank you for your help guys !!

Votes

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
community guidelines
Community Expert ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Here is a sample of how to load an external JSON file:

var that = this;

this.json = {};

this.loadJson = function(url)

{

    var queue = new createjs.LoadQueue(true);

    queue.on("fileload", that.onJsonLoaded, that);

    queue.on("error", that.onJsonLoadError, that);

    queue.loadFile({id:"json", src:url});

}

this.onJsonLoaded = function(e)

{

    that.json = e.target.getResult("json");

    that.setText();

}

this.onJsonLoadError = function(e)

{

    console.log(e);

}

this.setText = function()

{

    var songs = that.json.songs;

   

    for (var i = 0, total = songs.length; i < total; i++)

        that.txt.text = that.txt.text + "\n" + songs.name + ", " + songs.artist + ", " + songs.length + ", " + songs.track + ", " + songs.extension;       

}

this.loadJson("data.json");

FLA download:

animate_cc_html5_load_json.zip - Google Drive

I hope it helps.

Regards,

JC

Votes

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
community guidelines
Community Beginner ,
Apr 17, 2018 Apr 17, 2018

Copy link to clipboard

Copied

Thank you a lot ! I will try to understand how it works ! thanks for the file too !!

Votes

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
community guidelines
Explorer ,
Apr 18, 2018 Apr 18, 2018

Copy link to clipboard

Copied

Hey !

Thanks for the example but what I'm looking to do is a bit different.. In fact I try to load different fields in a movieclip. I understand you load everything into a single textfield but I have different textfields and each has its own value. Please check my code below to understand.

The movieclip contains 3 fields. One for the "titre" field, one for the "date" and one for the "description" field all in my "main_mc" movieclip. I have a movieclip into "main_mc" called "img_container" where want to load the image.

I would like Animate to display a list with all my elements.

Here is my code :

var root = this;

var proj = [];

$.ajax({

    type: 'GET',

    url: 'data_img.json',

    dataType: 'json',

    success: function (json) {

        proj = json;

        console.log(proj);

        renderImg();

    },

    error: function() {

        console.log("error");

    }

});

function renderImg() {

    for(var i=0; i<proj.length; i++){

        root.main_mc.txt.text = proj.titre;

        root.main_mc.txt2.text = proj.date;

        root.main_mc.description.text = proj.description;

        var bitmap = new createjs.Bitmap('images/' + proj.image);

        proj.bitmap = bitmap;

    }

    root.main_mc.txt.text = proj.titre;

    root.main_mc.txt2.text = proj.date;

    root.main_mc.description.text = proj.description;

    root.main_mc.img_container.addChild(proj.bitmap);

}

Here is my json file content:

json.png

Can you explain me why it doesn't work ?

I join a link with my Animate file: https://wetransfer.com/downloads/0911e08b3cb2c6f1061724064104ed1920180418083800/254ec09307c850d69d76...

Thanks a lot !!

Votes

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
community guidelines
Community Expert ,
Apr 18, 2018 Apr 18, 2018

Copy link to clipboard

Copied

Hi again!

- You need to include the jQuery library in your HTML (if you use any component from the Components panel, Animate will include for you automatically);

- These four lines:

root.main_mc.txt.text = proj.titre;

root.main_mc.txt2.text = proj.date;

root.main_mc.description.text = proj.description;

root.main_mc.img_container.addChild(proj.bitmap);

need to be inside the loop.

Please don't hesitate to ask if you have any further questions.

Regards,

JC

Votes

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
community guidelines
Explorer ,
Apr 18, 2018 Apr 18, 2018

Copy link to clipboard

Copied

Can't believe it was so simple to fix.. thank you for your help, all datas appear now !

Thanks a lot !

Votes

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
community guidelines
Community Expert ,
Apr 18, 2018 Apr 18, 2018

Copy link to clipboard

Copied

You're welcome!

Votes

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
community guidelines
Explorer ,
Apr 18, 2018 Apr 18, 2018

Copy link to clipboard

Copied

Hmm.. it's working now but it only displays the last info (third title etc.)

I included Jquery and here is my code:

var root = this;

var proj = [];

$.ajax({

    type: 'GET',

    url: 'data_img.json',

    dataType: 'json',

    success: function (json) {

        proj = json;

        console.log(proj);

        renderImg();

    },

    error: function() {

        console.log("error");

    }

});

function renderImg() {

    for(var i=0; i<proj.length; i++) {

        root.main_mc.txt.text = proj.titre;

        root.main_mc.txt2.text = proj.date;

        root.main_mc.description.text = proj.description;

        var bitmap = new createjs.Bitmap('images/' + proj.image);

        proj.bitmap = bitmap;

        root.main_mc.img_container.addChild(proj.bitmap);

    }

   

}

Any idea..?

Votes

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
community guidelines