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

Load external text in Animate

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

Views

5.6K

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

var r = new XMLHttpRequest(); 

r.addEventListener("load", rF);

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

r.send(); 

function rF(e) { 

alert(e.target.response);

}

Votes

Translate

Translate
Community Expert ,
Jul 26, 2018 Jul 26, 2018

Copy link to clipboard

Copied

html5/canvas or as3?

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

Copy link to clipboard

Copied

Yes HTML, can pls help me with that?

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 ,
Jul 26, 2018 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);

}

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 ,
Jul 27, 2018 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?

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 ,
Jul 27, 2018 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);

}

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 ,
Jul 27, 2018 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?

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 ,
Jul 27, 2018 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;

}

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 ,
Jul 27, 2018 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?

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 ,
Jul 27, 2018 Jul 27, 2018

Copy link to clipboard

Copied

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

}

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 ,
May 14, 2020 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

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 ,
Jul 26, 2018 Jul 26, 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
Contributor ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

I wonder for many things including why this works for me only in the preview window - directly opened by Animate. 

As I open exported HTML file in the browser - that external content doesn't show up anymore. Why?
I'm on the way to create the page where the Name on the screen will be chosen randomly from an external text file. It works less or more ok in AS but I can't figure out how to move it to HTML 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 Expert ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

what code are you using?

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
Contributor ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

The same from here marked as the correct answer. It does the thing only when hit cmd+Enter. After opening the HTML file from the disk none of the external content loads.

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 ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

what do you see when testing in animate?

what do you see when opening the html from your hard drive?

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
Contributor ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

When testing from Animate it shows some kind of pop-up window with the content of the external file and close button.
When I open rendered HTML file it just skips that place, just shows nothing as there is no any script - nothing. (all files are in the same folder, of course)

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 ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

create a new folder

save your fla to that folder

move the path folder (that contains file.xml) to that new folder

publish to that folder

test in animate.

test by opening the html in that new folder.

 

any problem?

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
Contributor ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

Does it work for everybody else? What I'm doing wrong?

 

Here are my files ...

https://www.dropbox.com/s/kxia3iilpu0c6ip/NewTest.zip?dl=0

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
Contributor ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

And there is another one strange thing:

In my folder are 4 files:
- project.fla

- names.txt

- index.html and -index.js (those 2 are rendered from project .fla export)

 

If I rename "names.txt" file to "names.xml" and open project.fla again it will preview the correct movie with loaded external file data even there is no that file anymore. It doesn't need to rewrite the source in the code.  What this could mean?

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 ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

then you're not using the code i suggested in the answer marked as correct.

 

so, copy (from your fla) and paste (here) the code you're using to load the xml file.

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
Contributor ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

var r = new XMLHttpRequest();
r.addEventListener("load", rF);
r.open("GET", "Names.txt", true);
r.send();
function rF(e) {
alert(e.target.response);
}

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 ,
Jan 22, 2021 Jan 22, 2021

Copy link to clipboard

Copied

the file you want to load should be renamed to Names.txt (and you'll probably have a cross-domain security issue (Same-origin policy - Wikipedia) if you try to open that text file on your local (computer) system.  ie, upload the files to a server and test.

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