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

Working example: How to populate "my_textfield" on the stage with some json data?

Community Beginner ,
Oct 28, 2017 Oct 28, 2017

I am in front of Animate CC and in the stage I have an instance of a dymamic textfield called "my_textfield".

How to populate "my_textfield" on the stage with some data in a json file?

Do you know a working code example?

Thanks a lot.

450
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 , Oct 28, 2017 Oct 28, 2017

use something like:

var this_var=this;

function parseResponseF(s){

this_var.my_textfield.text=s.name;

}

Translate
Community Expert ,
Oct 28, 2017 Oct 28, 2017

as3 or html5/js?

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
Community Beginner ,
Oct 28, 2017 Oct 28, 2017

Sorry...

with js in the actions panel.

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
Community Expert ,
Oct 28, 2017 Oct 28, 2017

add a component to your project (or otherwise include jquery) and use:

function sendDataF(methodS,dataTypeS,urlS,dataObj,f){

$.ajax({

    url : urlS,

    data : dataObj,

    type : methodS,

    dataType : dataTypeS,

    success : f,

    error: function(ts) { console.log(ts.responseStatus); },

    error : function(xhr, status) {

        var errorS = '';

        for(s in xhr){

            errorS += s+' : '+xhr+'\n';

        }

        alert('Sorry, there was a problem!\n'+errorS+'\nstatus:'+status);

    },

    complete : function(xhr, status) {

        var errorS = '';

        for(s in xhr){

            errorS += s+' : '+xhr+'\n';

        }

       // alert('request complete!\n'+errorS+'\nstatus: '+status);

       //console.log('request complete!\n'+errorS+'\nstatus: '+status);

    }

});

}

function parseResponseF(s){

    //parse s

}

sendDataF("POST","json","yourjasonfilename.json",null,parseResponseF);

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
Community Beginner ,
Oct 28, 2017 Oct 28, 2017

I have added a component to the proyect and I have replace the name of the json file (datos.json) containing an object in it. This is:

{

"name":"Jesper"

}

 

I don´t know how to parse it to populate "my_textfield" on the stage.

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
Community Expert ,
Oct 28, 2017 Oct 28, 2017

use something like:

var this_var=this;

function parseResponseF(s){

this_var.my_textfield.text=s.name;

}

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
Community Beginner ,
Oct 28, 2017 Oct 28, 2017

I am using Firebug on Mozilla and now I am getting the folowing warning in the console.log : The use of Mutation Events is out of date. Use MutationObserver instead.

However, it is working. Thank you kglad!

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
Community Expert ,
Oct 28, 2017 Oct 28, 2017
LATEST

you can comment out console.log if you're not using the developers edition of firefox (or use another browser that is compatible with debugging).

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

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