[Plugin] Call Javascript

0 favourites
From the Asset Store
Template: Jyruzz
$3.75 USD
50% off
Basic clone of a 80's arcade game called Gyruss that was quite fun to play!
  • hi,

    a plugin for executing Javascripts in runtime.

    (The plugin doesn't work in preview mode.)

    [Update]

    now the external javascriptfile-loading should work in all browsers <img src="smileys/smiley4.gif" border="0" align="middle">

    [/Update]

    callJS - Demo, Plugin, example Scriptfile

    another example: Call Google Maps

    The Plugin executes scripts/functions

    #) written in an external javascript file - ie myScripts.js

    #) coming out from construct - ie: 2+3+4 or the example with the browser name in the demo - you can write any script in a textbox and then execute it

    All suggestions are welcome. <img src="smileys/smiley2.gif" border="0" align="middle">

    Joe7

  • Joe7,

    I'm not exactly sure where to put the myscript.js, so the example keeps failing. I specified a the location in the capx before exporting, and I also put the myscript.js in the same folder as the index.html, but no go.

    I think i am missing something obvious.

  • hi Wastrel,

    have you changed the initial value of the Plugin to: myscript.js

    (the name is case sensitiv)

    you should place your script file next to your index.html

    <img src="http://dl.dropbox.com/u/31151399/Construct2/Plugins/callJSHowTo/whereIsTheScript.png" border="0" />

    hope that helps, Joe7

  • jQuery.getScript(this.nameOfExternalScript, function(){});

    I like it!

    This method is better then mine. I use AJAX to load js file, then save in plugin.

  • Yes, that clears it up. I will test it out. Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • jQuery.getScript(this.nameOfExternalScript, function(){});

    this line looks nice but was bad for other browsers as firefox

    • i've changed it now and load the external file with pure javascript+dom

    => now the loading of the external-script should work <img src="smileys/smiley2.gif" border="0" align="middle" />

  • I embarqued this morning on a project for a plugin to manipulate & change the URLs, and I remembered your nice plugin. It's way more quicker to use it to do things like that !

    So, here's an example, which shows how to change the url you are currently browsing when clicking on a button inside C2's canvas. Beware, everything you were doing on your game can be lost !

    I added a second button. When you click on the first one to go to google (for example), and go back with the 'back' button of your browser, you can use the second button to navigate forward in the history tree.

    http://dl.dropbox.com/u/1412774/URLs_and_Timeouts.capx

  • How can i use this :

    Its in javascript but not working..

    $.post("https://www.scoreoid.com/api/getNotification", { api_key: "Your API Key", game_id: "Your Game ID", response: "JSON"},

       function(data) {

         alert("Data Loaded: " + data);

       },

    "json"

    );

    Obviously i changed the details with my API key ect..

  • Excellent! This makes the question of adding a stack to my "learning C2" game simple! Thank You! <img src="smileys/smiley32.gif" border="0" align="middle" />

  • >

    jQuery.getScript(this.nameOfExternalScript, function(){});

    >

    this line looks nice but was bad for other browsers as firefox

    - i've changed it now and load the external file with pure javascript+dom

    => now the loading of the external-script should work <img src="smileys/smiley2.gif" border="0" align="middle" />

    Interesting... getScript is what I use in my plugin so it looks like I'll have to do a little more testing.

    Quick question. What do you do to include the .js file when the project is exported? I wanted to load my script from an external location, but fall back to a local version if it's unavailable. But the only way I could find to include the script during export was to set dependency in edittime, but that also automatically adds the script to the html thus making the remote loading useless.

  • What do you do to include the .js file when the project is exported?

    Nothing. <img src="smileys/smiley17.gif" border="0" align="middle"> The scriptfile has to be somewhere where it'll be found - e.g next to the index.html (->write only the filename in the properties) or in a folder next to the index.html (e.g myScripts/myScripfile.js).

    you can also refer to a scriptfile somewhere over the rainbow in the properties of the plugin: dl.dropbox.com/u/31151399/Construct2/Examples/callGoogleMaps/myScripts.js

    http://dl.dropbox.com/u/31151399/Construct2/Examples/callGoogleMaps/myScripts.js

  • for those wondering why execute action doesn't work in any layout but the first one, you have to make calljs object global. just stumbled on it :)

    great plugin, cheers!

  • Thanks ranma for the tip.

    _____________

    HowTo - Preview and use custom-javascript-functions written in a scriptfile:

    (Local)-preview is still working all the time - but under the circumstance that the Scripfile is 'online' (- eg: Path: dl.dropbox.com/u/31151399/Construct2/Examples/callGoogleMaps/myScripts.js).

    I know that this is not nice and not userfriendly but on the other hand I think it's not the biggest problem to save in the scriptfile in a dropboxfolder. (capx)

    <img src="smileys/smiley2.gif" border="0" align="middle">

  • Hi joe.

    I have a one problem with using callJS plugin.

    Could you help me to solve my problem?

    I made a .js file and I compiled and executed it. It was good.

    But when I called a my .js file on callJS plugin,

    it didn't work. Sentence of error by callJS is below

    "ReferenceError : a is not defined"

    'a' is variable. This .js file is working good on normal web browser, such as chrome or whatever.

    I thought a loading time of custom .js file is later than c2runtime.js file,

    so declared variable in my .js file could not load in callJS plugin.

    Sorry for disturbing your work,

    I hope you'll answer my question.

    Thank you.

    karl

  • rememberkarl

    Have you tried to manually include your js-file in the index.html? ( copy the line of the loading of the c2runtime.js and change the first to your script) The plugins adds the loading in the head of the index.html but after the c2runtime is called.. hope that helps..

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