Site calls an action within the game

Get help using Construct 2

Post » Fri Sep 19, 2014 12:11 am

Hi,
I have a website with my game in an iframe.
I need that when you click a button on my site (outside the game), perform an action within the game, which is in an iframe. Is this possible?
B
5
S
2
Posts: 10
Reputation: 691

Post » Fri Sep 19, 2014 12:14 am

What's the action?
B
62
S
23
G
10
Posts: 648
Reputation: 10,580

Post » Fri Sep 19, 2014 1:42 am

Include the function object in your c2 project, then you can call functions with
iframe.contentWindow.c2_callFunction("Func",[]);

Edit: Where "Func" is the name of the function to call and [] is an array of arguments.
B
11
S
2
G
1
Posts: 202
Reputation: 1,580

Post » Fri Sep 19, 2014 7:47 am

Noncentz705 wrote:Include the function object in your c2 project, then you can call functions with
iframe.contentWindow.c2_callFunction("Func",[]);

Edit: Where "Func" is the name of the function to call and [] is an array of arguments.


Thanks for this. Is it possible on client side to have the C2 iframe call the parent container's js?
B
32
S
7
G
2
Posts: 317
Reputation: 2,851

Post » Fri Sep 19, 2014 9:05 am

@IndieKiwi window.parent to control the parent window.
Example : window.parent.document.body.style.background = "blue";

But it's worth noting that c2_callFunction can return a value;
It might save you the hassle of playing with JS inside your c2 project.
B
11
S
2
G
1
Posts: 202
Reputation: 1,580

Post » Fri Sep 19, 2014 1:15 pm

Cool, man!
That was exactly what I was looking for.
It worked perfectly.
Thank you so much!
B
5
S
2
Posts: 10
Reputation: 691

Post » Thu Dec 29, 2016 10:02 am

Sorry for reopen this old post

I need to make the same action:
-> call a function C2 on a button placed out the project

I tried to call "c2_callFunction()" from js code placed in index.html C2 but i had always error 'c2_callFunction is not defined'

Is it really possible to use this function from external code or it is only a function to develop C2 plugin ?
B
19
S
4
Posts: 84
Reputation: 2,110

Post » Fri Jul 07, 2017 1:15 pm

Me too! error 'c2_callFunction is not defined'
Help please.
Thanks
B
6
S
1
Posts: 56
Reputation: 516


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests