How do I link to a project file?

  • Hi! I use the Sprite's "Load image from url" action, but I have a problem with the file's url: the manual says that any project file's url looks like "image.png" - and this works, but ony when previewing. When I export it (PhoneGap) it doesn't work at all. I guess this is because I locate project files in subfolders (e.g. Files/Images/subfolder/image.png), do I have to link project files with the full subfolder-path? For example "Images/subfolder/image.png". And if this is the problem, why does it affect only the exported version?

    Thank you for your help.

  • Anybody?

  • Check and make sure you can load it in a browser first. If not, get the URL correct, then try loading it in your C2 app.

  • gumshoe2029

    the manual says that any project file's url looks like "image.png" - and this works, but ony when previewing.

    As I said, there is no problem testing in a browser. Does anybody know where the problem is? Do I have to report it as a bug??

  • Ok, now I'm really clueless: when I export, "Load image from url Project File" only works if that image is one of the C2 icons that come by default in every capx (by the way, they are undeletable, they reappear if you try to remove them!). If you try to load any other image, it simply doesn't work. Please any kind of help would be truly appreciated.

  • If it only affects the exported version, it may be because the image you are linking to is redirected. Your computer and the phone may handle the redirection differently. When you open the image in your browser, do you get redirected to another URL? Does the "copy image link" gives you anything differently ?

    In some rare cases, the website can block loading outside of specific useragent too, but this is not common at all.

  • And the exported app is running on your phone ? Do you have access to localhost on your phone, by being on the same wifi ? You may need to host it online if you want to do it like that, localhost is local. I may have missed something obvious though, sorry if I did

  • Guizmus Yes, I export to Cordova and run my app on Android. I did preview over LAN in my mobile phone (yes, being on the same WiFi) and there was no problem at all. As I said, problem comes only when you run the APK file. I made a test capx where I can trigger the "Load image from URL" action in different ways and with different images, and it only worked with the C2 icons. This makes me suspect that it is either a bug that has to be reported or that project files have to be somehow preloaded before being shown (and for some reason C2 icons are automatically preloaded, I guess). What do you think?

  • It would be strange that it would have not been reported, but maybe... Did you try preloading the image in a sprite you don't show, prior to loading for your real object ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok I found a bad and dirty workaround (not a solution yet):

    AJAX Request project file ("image.png")
    On AJAX Request completed --> Sprite Load image from "image.png"
    [/code:84w8ia35]
    BUT I will have to do an AJAX Request every single time I want to load a new image and this solution doesn't work for html code
    For example:
    [code:84w8ia35]<img src="image.png" height="100px" />[/code:84w8ia35]
  • I think this is a header problem.

    Construct is very... legal.

    If you don't include the CORS (I think it is CORS?) header then Construct will simply not load your image, assuming that you are trying to 'steal' your own image.

    In theory, loading images from the project directories should bypass this issue, but maybe not?

    Can you not integrate this image into the sprite itself? Or is it dynamic?

  • gumshoe2029 Thank you for your answer!

    I'm not really an expert in CORS, does this mean I have to add

    Access-Control-Allow-Origin: *[/code:1bzjodyy] to my index.html's header? And if it was a header problem, why doesn't it affect to the C2 logo? (For example, icon-114.png loads as expected, while any other image does not).
    
    I could integrate the image(s) in a sprite, but what I really want this for is to be able to access that image(s) from HTML code, like [code:1bzjodyy]<img src="image.png" ... />[/code:1bzjodyy] I am starting to consider whether this is a bug, and if it is not, this isn't documented at all! Maybe Scirra could throw a bit of light on this...
  • And if it was a header problem, why doesn't it affect to the C2 logo? (For example, icon-114.png loads as expected, while any other image does not).

    ea, I agree this is the part that doesn't make sense. It shouldn't affect image files in the project directory.

    I could integrate the image(s) in a sprite, but what I really want this for is to be able to access that image(s) from HTML code, like

    <img src="image.png" ... />[/code:rw07jwg1] I am starting to consider whether this is a bug, and if it is not, this isn't documented at all! Maybe Scirra could throw a bit of light on this...
     would try hosting the image in a Apache webserver directory (htdocs on Windows) and set the httpd.conf (make sure to include the headers.so module) file to include a [code:rw07jwg1]Header set Access-Control-Allow-Origin "*"[/code:rw07jwg1] line.  You can install Apache webserver on Windows, but it takes a bit of coaxing, or if you dont mind installing PHP and MySQL, you can just use a [url=https://bitnami.com/stack/wamp/installer]WAMP stack[/url].

    I suspect the issue is in the loading mechanics, and some security mechanism that is throwing wrenches into your implementation. It feels like a server/security issue.

    You will need a web server to test your final exported C2 app anyway. :-p

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