Skip to main content
Known Participant
Nov 18, 2020 2:42 AM UTC
Question

Importing external text to dynamic text Html5 canvas

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 is closed to new replies. Start a new post to keep the conversation going.

    12 replies

    Known Participant
    Nov 26, 2020 2:08 AM UTC

    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.

    🙂

    Translate
    Participant
    Nov 22, 2021 9:55 AM UTC

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

     

    Translate
    Known Participant
    Nov 18, 2020 6:48 PM UTC

    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?

     

    Translate
    kglad
    Community Expert
    Community Expert
    Nov 18, 2020 7:40 PM UTC

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

    Translate
    Known Participant
    Nov 19, 2020 3:30 AM UTC

    Could you please read my above response. Please.

    Translate
    kglad
    Community Expert
    Community Expert
    Nov 18, 2020 1:21 PM UTC

    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

    Translate
    Legend
    Nov 18, 2020 6:00 PM UTC

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

    Translate