How do I link to a project file?

Get help using Construct 2

Post » Thu Sep 28, 2017 10:55 am

Ok I found a bad and dirty workaround (not a solution yet):

Code: Select all
AJAX Request project file ("image.png")
On AJAX Request completed --> Sprite Load image from "image.png"

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: Select all
<img src="image.png" height="100px" />
B
21
S
7
G
1
Posts: 164
Reputation: 1,910

Post » Thu Sep 28, 2017 3:52 pm

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?
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Thu Sep 28, 2017 5:40 pm

@gumshoe2029 Thank you for your answer!

I'm not really an expert in CORS, does this mean I have to add
Code: Select all
Access-Control-Allow-Origin: *
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: Select all
<img src="image.png" ... />
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...
B
21
S
7
G
1
Posts: 164
Reputation: 1,910

Post » Sat Sep 30, 2017 3:54 pm

ChesVCF wrote: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).
Yea, I agree this is the part that doesn't make sense. It shouldn't affect image files in the project directory.

ChesVCF wrote: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: Select all
<img src="image.png" ... />
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...
I 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: Select all
Header set Access-Control-Allow-Origin "*"
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 WAMP stack.

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
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests