[Plugin] Call Javascript

Post your completed addons to share with the community

Post » Sat Feb 04, 2012 6:25 pm

What do you do to include the .js file when the project is exported?
Nothing. 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: http://dl.dropbox.com/u/31151399/Construct2/Examples/callGoogleMaps/myScripts.js

http://dl.dropbox.com/u/31151399/Construct2/Examples/callGoogleMaps/myScripts.jsJoe72012-02-04 18:26:37
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Thu Mar 01, 2012 2:25 pm

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!
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Sun Apr 08, 2012 10:39 am

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: http://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)

Joe72012-04-08 10:46:15
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Mon Apr 23, 2012 7:52 am

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.
karlrememberkarl2012-04-23 07:54:24
B
9
Posts: 9
Reputation: 609

Post » Tue May 01, 2012 1:49 pm

@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..Joe72012-05-01 13:51:27
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Wed May 02, 2012 3:19 am

Thank you.
I've solved my problem.
I call my function after system is loaded by using timeout.
B
9
Posts: 9
Reputation: 609

Post » Mon Sep 10, 2012 9:51 am

if you can't get calljs to work on cocoonjs (and probably direct canvas also), open plugin's runtime.js file and edit it around line 49:

change this:

this.nameOfExternalScript = this.properties[0];
          this.returnValue= "";
          var myScriptTag=document.createElement('script');
          myScriptTag.setAttribute("type","text/javascript");
          myScriptTag.setAttribute("src", this.nameOfExternalScript);
          
          if (typeof myScriptTag != "undefined")
               document.getElementsByTagName("head")[0].appendChild(myScriptTag);



to this:


if (typeof this.properties[0] != "undefined" && this.properties[0] != "") {
this.nameOfExternalScript = this.properties[0];
          this.returnValue= "";
          var myScriptTag=document.createElement('script');
          myScriptTag.setAttribute("type","text/javascript");
          myScriptTag.setAttribute("src", this.nameOfExternalScript);
          
          if (typeof myScriptTag != "undefined")
               document.getElementsByTagName("head")[0].appendChild(myScriptTag);
}



and it should work, but remember to clear the plugin's Scriptfile property (it must be empty for it to work with cocoonjs). this change should be done in original plugin also to prevent creating empty <script> tag.

hope I helped anyone :)
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Mon Sep 10, 2012 12:48 pm

can calljs work when exported to exe?
Also can we include external apis? For example if I have an api that does something can I still write a js file that accesses that api?

Thanks
B
6
S
1
Posts: 8
Reputation: 591

Post » Mon Nov 26, 2012 11:42 pm

I haven't looked at it yet, I'm on my iPad. Is it possible to return values to a construct2 variable? If I were to use this to fetch data from say Facebook, how do I then get the returned info into a usable construct variable?

Thanks
B
68
S
21
G
15
Posts: 701
Reputation: 15,604

Post » Tue Nov 27, 2012 10:33 pm

I all,

Thank you very mutch for the plugin.
But I think there's a small "issue".

I would like to pass a construct2 variable parameter to the fonction I call.

Exemple for the demo file :
Instead of doing sum(12,13), if I would like to make sum(x,y), x and Y are construct 2 variables. How should I do that.

If I put a variable in construct 2 and I make Execute sum(X,Y, it doesn't seems to work.
It acts as if it pass variables to javascript without affecting X and Y construct2 variables.

Sorry for my poor english.
I hope it will be well understanding.

If someone has a solution, it will be greatly appreciated.

Kind regards !
Thibaut
B
8
Posts: 8
Reputation: 516

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 4 guests