Skip to main content
Known Participant
November 18, 2020
Question

Importing external text to dynamic text Html5 canvas

  • November 18, 2020
  • 3 replies
  • 2203 views

I am very new to javascropt so keep answers simple please.

I have a dynamic text field with the instance name "Genealogy". I would like to load an external text file named "Genealogy.txt" file to it. I did it with flash before. How do I do it  in an html5 canvas document using javascript?
Keep it simple please. (A newbee with javascript)

🙂

Thank you in advance for your help.

    This topic has been closed for replies.

    3 replies

    Known Participant
    November 26, 2020

    Thanks for what little bit of help you gave me But know of you even came close to soving my problem. You can clewarly see what I am trying to do at this link, I don't need to hire any of you because it is something I have already done in Flash as you cna see if you wnat to takke the time to go to the link below.

    https://the4gnetwork.com/Charts/GenealogyOfJesus/GenealogyOfJesus.html 

    Look fast it will be gone soon.

    🙂

    Participant
    November 22, 2021

    Can you let us all know how was it done @terryj41605550 ?

     

    Known Participant
    November 18, 2020

    Okay, are you saying that I cannot load a plain txt file to a dynamic text instance in a html5-canvas?
    I gave you the instance name (Genealogy) And the file name I am trying to load (Genealogy.txt). Would it be possible for you to use those names in your example code. It would make your example much easier to understand. Please remember I am very new to JavaScript for an Html5-canvas. Furthermore is there not a ''scrollbar' component for html5-canvas? If the text file is larger than the dynamic text instance, can I add a scrollbar to the text instance?

     

    kglad
    Community Expert
    Community Expert
    November 18, 2020

    yes, you can use a . txt file as shown in the sample code.

    Known Participant
    November 19, 2020

    Could you please read my above response. Please.

    kglad
    Community Expert
    Community Expert
    November 18, 2020

    use an xml instead of plain text.  so, for example, instead of:

     

    file.txt containing "this is the next in file.txt"

     

    use:

     

    <tag1>this is the text in file.txt</tag1>

     

     

    and in animate use:

     

    var r = new XMLHttpRequest();
    r.open("GET", "file.txt", true);
    r.addEventListener("load", rF);
    r.send();

    function rF(e) {
    parser = new DOMParser();
    var xml = parser.parseFromString(e.target.response, "text/xml");
    alert(xml.getElementsByTagName("tag1")[0].childNodes[0].nodeValue);
    }

     

    p.s. if you're extracting anything other than the entire text or parsing that text, use a proper xml file

    Legend
    November 18, 2020

    If memory serves, XHR can load any arbitrary data, not just XML. A plain text file should be fine.