How do I call external javascript function from the tool?

Discussion and feedback on Construct 2

Post » Thu Dec 04, 2014 5:30 am

Hi all,

I want to run custom code from the tool and at the same time i want to pass objects values(score,total) with out using HTTP call.Is it possible?


Please kindly assist us.
B
4
S
1
Posts: 10
Reputation: 370

Post » Thu Dec 04, 2014 11:24 am

Use the Browser object.
Scirra Founder
B
403
S
238
G
89
Posts: 24,654
Reputation: 196,155

Post » Thu Dec 04, 2014 2:09 pm

Thanks Ashley,

I did that,Now am able to display object values in alert using "browse".But, where i have to specify the path of external javascript and how can i get that object values in external js file.Please tell me.

Please see the code

"javascript:function myFunction() {
alert('"& qn_id.Text &"');
}myFunction();"


:)
B
4
S
1
Posts: 10
Reputation: 370

Post » Thu Dec 04, 2014 2:39 pm

For anything more than passing strings to eval(), which is all the Browser object does, you should use our Javascript SDK. Also this is not the right place to ask general Javascript questions, there are other better sites for that (e.g. StackOverflow).
Scirra Founder
B
403
S
238
G
89
Posts: 24,654
Reputation: 196,155

Post » Fri Dec 05, 2014 6:10 pm

Much love for StackOverflow. You definitely need to make use of that site.

As for your specific question, you are going to have to modify the index.html file that Construct generates to integrate your js file into the overall page load. Otherwise, it doesn't know where you are asking it to go. By extension, this also means that calling js functions with the Browser object will NOT work in preview mode, since Construct knows nothing about the extra js file or the include that you have included manually in the published version.
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 » Fri Dec 05, 2014 6:28 pm

@gumshoe2029 - the Javascript SDK allows you to include scripts which also work in preview mode, and doesn't require any modification after export.
Scirra Founder
B
403
S
238
G
89
Posts: 24,654
Reputation: 196,155

Post » Tue Dec 09, 2014 5:14 pm

Oh, this is good to know. I will have to do some research on that. I just include it in the published index.html, and I used an if statement with AJAX calls to get the same info in preview mode.

Thanks @Ashley
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 » Tue Feb 10, 2015 12:22 am

DId you get to make the external call with the Execute Javascript action?
B
4
Posts: 5
Reputation: 210


Return to Construct 2 General

Who is online

Users browsing this forum: BiffanyPFH and 7 guests