Is it possible to have a dependency to a external file (http

For developers using the Construct 2 Javascript SDK

Post » Tue Apr 21, 2015 11:50 am

In my javascript SDK I want this because I need to include a script source with a unique key, like:

"http://www.mapquestapi.com/sdk/leaflet/v1.s/mq-map.js?key=UNIQUEKEYHERE"
B
3
Posts: 7
Reputation: 191

Post » Tue Apr 21, 2015 10:40 pm

FYI, my current workaround is as follows:
I just change the generated index.html to include

<script src="http://open.mapquestapi.com/sdk/leaflet/v1.s/mq-map.js?key=UNIQUEKEY></script>

However I (officially) have to do that every time I generate executable code and I lose the advantage of running the capx from within construct 2
B
3
Posts: 7
Reputation: 191

Post » Thu Apr 23, 2015 5:55 pm

Dependency are defined in the edittime.js file. As per the manual :

TFM wrote:dependency
This one isn't listed above, but if you need external files bundled with your plugin (e.g. a javascript library) you can specify one or more dependency files with:

Code: Select all
"dependency": "file1.js;file2.js;file3.html"

B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Thu Apr 23, 2015 6:06 pm

Thank you.

However that does not work with files that are not stored in the plugin folder AFAIK, such as in OP.
B
3
Posts: 7
Reputation: 191

Post » Sun Apr 26, 2015 11:34 pm

hey , in your plugin runtime.js , in the function "onCreate"

add this

$.getScript( "YOUR SCRIPT URL", function( data, textStatus, jqxhr )
{
// when the script is loaded here you can use it :D
});

Have fun making plugins :D
B
28
S
9
G
9
Posts: 294
Reputation: 7,064

Post » Tue May 12, 2015 4:15 pm

Thank you.
B
3
Posts: 7
Reputation: 191

Post » Wed May 27, 2015 10:46 pm

you are welcome
B
28
S
9
G
9
Posts: 294
Reputation: 7,064

Post » Wed Jun 10, 2015 1:38 pm

hmmg wrote:hey , in your plugin runtime.js , in the function "onCreate"

add this

$.getScript( "YOUR SCRIPT URL", function( data, textStatus, jqxhr )
{
// when the script is loaded here you can use it :D
});

Have fun making plugins :D


Thats not a good idea. I have tried this in x versions.
Thats a async load, it much times comes to late!
You can try it with sync load, but best to be sure its loaded correctly, is to have it in your addons and load it in edittime!

Code: Select all
jQuery.ajax({
    async:false,
    type:'GET',
    url:script,
    data:null,
    success:callback,
    dataType:'script',
    error: function(xhr, textStatus, errorThrown) {
        // Look at the `textStatus` and/or `errorThrown` properties.
    }
});
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
10
S
4
G
1
Posts: 158
Reputation: 1,303

Post » Wed Jun 10, 2015 1:54 pm

@deathangel1479 , onCreate is loaded before the game started , and the script size is at max 50Ko , it's not that hard loading ,

@stefan52a you can use this the sync loading with ajax

$.ajax({
url: "SCRIPT_URL",
dataType: "script",
async: false,
success:function()
{
// when the script is loaded here you can use it
}
});

or here is a better one , add it inside the onCreate

$("head").append('<script src="http://open.mapquestapi.com/sdk/leaflet/v1.s/mq-map.js?key=UNIQUEKEY></script>');
B
28
S
9
G
9
Posts: 294
Reputation: 7,064

Post » Wed Jun 10, 2015 3:25 pm

If construct project is in cache, its real fast +- some ms between "onCreate" and "onLayoutStart", and I only say that it can be, in especially if you have a fast system and slow internet. I would not count on it, to much unknown!
I had much errors with unloaded stuff, but was also a big script... 128KB
Yes, sync is much better.
I think .append() is also async, not?
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
10
S
4
G
1
Posts: 158
Reputation: 1,303

Next

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests