How do I load an Image from a URL after the game starts

Get help using Construct 2

Post » Wed Nov 25, 2015 9:12 am

.
Last edited by danieltpt on Tue Dec 15, 2015 1:57 pm, edited 1 time in total.
B
10
S
3
G
5
Posts: 35
Reputation: 3,323

Post » Wed Nov 25, 2015 9:14 am

.
Last edited by danieltpt on Tue Dec 15, 2015 1:57 pm, edited 1 time in total.
B
10
S
3
G
5
Posts: 35
Reputation: 3,323

Post » Wed Nov 25, 2015 9:37 am

]
Last edited by danieltpt on Tue Dec 15, 2015 1:58 pm, edited 1 time in total.
B
10
S
3
G
5
Posts: 35
Reputation: 3,323

Post » Wed Nov 25, 2015 9:38 am

For instance, using the following image in your .capx from wikipedia works:

Code: Select all
https://upload.wikimedia.org/wikipedia/en/e/e7/Construct2Logo.png


CORS is about cross domain security. More info in the AJAX manual entry HERE.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
86
Posts: 5,483
Reputation: 59,752

Post » Wed Nov 25, 2015 3:07 pm

.
Last edited by danieltpt on Tue Dec 15, 2015 1:58 pm, edited 1 time in total.
B
10
S
3
G
5
Posts: 35
Reputation: 3,323

Post » Wed Nov 25, 2015 3:12 pm

From the link @zenox98 gave:

Making AJAX requests cross-domain or in preview

By default, browsers block AJAX requests across domains. This means, for example, a game on scirra.com can request other pages on scirra.com, but cannot request pages on facebook.com. This is an important security feature of web browsers (it is not specific to Construct 2 or its AJAX object).

Also, when previewing in Construct 2 the game runs on localhost. This counts as a different domain to the rest of the internet, so typically AJAX requests to any web page will fail during preview, unless the server explicitly allows cross-domain requests.

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: *

This will enable AJAX requests from any domain, but you should still be aware of the possible security implications of this. For more information on cross-domain requests see HTTP access control on MDN.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Nov 25, 2015 3:16 pm

It all depends on what you are attempting to do and why you are wanting to load from URL.

IF you read what I have linked you will see that a server would need to be configured to allow such 'hot linking' to an image. This is an important browser security feature and nothing to do with C2.

If both your end product and images are to be hosted on the same server, then you probably won't have an issue.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
86
Posts: 5,483
Reputation: 59,752

Previous

Return to How do I....?

Who is online

Users browsing this forum: Artcadev and 6 guests