Highlighted

Load external text in Animate

Community Beginner ,
Jul 26, 2018

Copy link to clipboard

Copied

Hello, in flash we was able to load text in dynamic text field from external .XML file. Does anyone know how can I do that in Adobe Animate?

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

var r = new XMLHttpRequest(); 

r.addEventListener("load", rF);

r.open("GET", "path/file.xml", true);  

r.send(); 

function rF(e) { 

alert(e.target.response);

}

Views

1.4K

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

Load external text in Animate

Community Beginner ,
Jul 26, 2018

Copy link to clipboard

Copied

Hello, in flash we was able to load text in dynamic text field from external .XML file. Does anyone know how can I do that in Adobe Animate?

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

var r = new XMLHttpRequest(); 

r.addEventListener("load", rF);

r.open("GET", "path/file.xml", true);  

r.send(); 

function rF(e) { 

alert(e.target.response);

}

Views

1.4K

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
Jul 26, 2018 0
Adobe Community Professional ,
Jul 26, 2018

Copy link to clipboard

Copied

html5/canvas or as3?

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...
Jul 26, 2018 0
Community Beginner ,
Jul 26, 2018

Copy link to clipboard

Copied

Yes HTML, can pls help me with that?

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...
Jul 26, 2018 0
Adobe Community Professional ,
Jul 26, 2018

Copy link to clipboard

Copied

var r = new XMLHttpRequest(); 

r.addEventListener("load", rF);

r.open("GET", "path/file.xml", true);  

r.send(); 

function rF(e) { 

alert(e.target.response);

}

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...
Jul 26, 2018 0
Community Beginner ,
Jul 27, 2018

Copy link to clipboard

Copied

Thanks a lot, can you tell me the code to load the text in the txt field? Do you got any idea how can I choose which node to be loaded from the XML file?

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...
Jul 27, 2018 0
Adobe Community Professional ,
Jul 27, 2018

Copy link to clipboard

Copied

if you have a node named filename:

function rF(e){

parser = new DOMParser();

var xml = parser.parseFromString(e.target.response, "text/xml");

alert(xml.getElementsByTagName("filename")[0].childNodes[0].nodeValue);

}

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...
Jul 27, 2018 0
Community Beginner ,
Jul 27, 2018

Copy link to clipboard

Copied

Thanks a lot. That is great. I had problem to load that text in the text field. I am sorry for asking again but what is the code to load that node text in the text field?

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...
Jul 27, 2018 0
Adobe Community Professional ,
Jul 27, 2018

Copy link to clipboard

Copied

function rF(e){

parser = new DOMParser();

var xml = parser.parseFromString(e.target.response, "text/xml");

your_tf.text = xml.getElementsByTagName("filename")[0].childNodes[0].nodeValue;

}

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...
Jul 27, 2018 0
Community Beginner ,
Jul 27, 2018

Copy link to clipboard

Copied

so if the name of the text field is "alert"  that will work? The problem is that I can not make the text field to load that value taken from the XML?

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...
Jul 27, 2018 0
Community Beginner ,
Jul 27, 2018

Copy link to clipboard

Copied

Thanks a lot

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...
Jul 27, 2018 0
Adobe Community Professional ,
Jul 27, 2018

Copy link to clipboard

Copied

you're welcome.

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...
Jul 27, 2018 0
Community Beginner ,
Jul 27, 2018

Copy link to clipboard

Copied

We did improve what you send: here how it looks like. Now you can load only once the XML file and later by using _this.xml you can load any content in the animation without reloading the XML file. Cheers!

var _this = this;

_this.r = new XMLHttpRequest();

_this.r.addEventListener("load", rF);

_this.r.open("GET", "test.xml", true);

_this.r.send();

function rF(e) {

if(typeof _this.xml === "undefined"){

parser = new DOMParser();

_this.xml =parser.parseFromString(e.target.response, "text/xml");

    }

    _this.example.text = _this.xml.getElementsByTagName("to")[0].childNodes[0].nodeValue

}

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...
Jul 27, 2018 0
New Here ,
May 14, 2020

Copy link to clipboard

Copied

Could I possibly see the structure of the XML file so I can understand how to structure mine as cannot seem to get text and get a 'null' alert response.

 

Thanks

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...
May 14, 2020 0
Adobe Community Professional ,
Jul 26, 2018

Copy link to clipboard

Copied

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...
Jul 26, 2018 1