Skip to main content
Participating Frequently
October 28, 2017
Answered

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

  • October 28, 2017
  • 1 reply
  • 539 views

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.

    This topic has been closed for replies.
    Correct answer kglad

    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.


    use something like:

    var this_var=this;

    function parseResponseF(s){

    this_var.my_textfield.text=s.name;

    }

    1 reply

    kglad
    Community Expert
    Community Expert
    October 28, 2017

    as3 or html5/js?

    @rrowmanAuthor
    Participating Frequently
    October 28, 2017

    Sorry...

    with js in the actions panel.

    kglad
    Community Expert
    Community Expert
    October 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);