How do I load text and image from an external txt file?

0 favourites
  • 5 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • I know that is possible to load text from a internal txt file. But I don't know how to import text from an external txt file using json. Is it possible to load images from links through a txt file too? I'll really appreciate if anyone explain to me how to do this. Thanks.

  • Hi Braus,

    you can request external file contents with ajax from an URL (i think that is what you mean with external?)

    Take a look at the ajax object https://www.scirra.com/manual/107/ajax request from URL.

    [quote:w0w1sf2b]Request URL

    Send a GET request to retrieve the contents of a URL. A tag is provided to match it up with the On completed, On progress and On error triggers.

    The contents could also be a link to an image.

    You can then set the AJax.lastData to the sprite you want to load the image to.

    [quote:w0w1sf2b]Load image from URL

    Load an image from a given URL. The current animation frame will be replaced with the image. It is not shown until the image has finished downloading, and On image URL loaded triggers. Images loaded from different domains are subject to the same cross-domain restrictions as AJAX requests - for more information see the section on cross-domain in the AJAX object. Data URIs can also be passed as an image, e.g. from a canvas snapshot or webcam image. The Size parameter sets whether the Sprite object will be set to the image size when it loads, or whether to keep its current size and stretch the image.

    If you want to test locally dont forget to enable ajax requests from all sources in your hosting

    [quote:w0w1sf2b]If you want AJAX requests to your server to work from any domain, or in preview, you can configure it to send the following HTTP header:

    Access-Control-Allow-Origin: *

    I hope that helps <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi j0schi

    Thanks for these confirmations. I still not understood how can I do to request the URL for images links and text files? Using a specific action or the same that I use to request a internal txt file? I need to get the image link on the text file (the same that I use to store the text informations, is possible?) How cai I use AJax.lastData to load the image?

    I have another big question (at least for me): can I use both (internal and external) files depending if mobile has or not internet connection? If yes, can you explain to me how to do this?

  • Hi Braus,

    here is one way to do it:

    please note that the imageurl.txt has to contain the url to the actual image. you can also request php files this way whcih gives out another image depending on the url request. there are several other ways too...

    you can also check with the Browser Object "is online" but i think that would not be necessary as you want to handle any connection error...

    i hope that this point you in the right direction

    regards

  • Great, j0schi

    It's very clear for me now. I'll try to apply these instructions. Thanks a lot.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)