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

Load external text in Animate

Community Beginner ,
Jul 26, 2018 Jul 26, 2018

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?

7.4K
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 , 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);

}

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

html5/canvas or as3?

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

Yes HTML, can pls help me with that?

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 ,
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);

}

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

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?

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

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);

}

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

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?

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

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;

}

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

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?

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

Thanks a lot

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

you're welcome.

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

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

}

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

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

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

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.

 

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

what code are you using?

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

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.

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

what do you see when testing in animate?

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

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

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)

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

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?

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

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

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

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?

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

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.

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

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

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

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.

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