Call function from another extension in same zone as1
- kotbegemot
- Posts: 82
- Joined: 21 Nov 2010, 05:05
- Location: Saint-Petersburg
Call function from another extension in same zone as1
Is it possible to call function from one extension to another in one zone ?
hi. Yes it is possible. You need to use the handleInternalRequest function of an extension (that is similar to the handleRequest) or you can use your own function.
To acces another extension, you can use the zone.getExtension("extensionName") method, and store that extension reference in a var.
Finally, to call a function of that extension, you do extension.myFunction(myParam) where extension is a reference to the extension.
Here.s an example code for a zone extension(written on mobile so may have some errors):
Theres a chapter on www.smartfoxserver.com/docs which talks a little about this.
EDIT
Its the chapter 6.11
To acces another extension, you can use the zone.getExtension("extensionName") method, and store that extension reference in a var.
Finally, to call a function of that extension, you do extension.myFunction(myParam) where extension is a reference to the extension.
Here.s an example code for a zone extension(written on mobile so may have some errors):
Code: Select all
var zone = _server.getCurrentZone()
var myExtension = zone.getExtension("myExtension")
myExtension.doMethod()
Theres a chapter on www.smartfoxserver.com/docs which talks a little about this.
EDIT
Its the chapter 6.11
Last edited by rjgtav on 14 Jul 2011, 12:38, edited 2 times in total.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
- kotbegemot
- Posts: 82
- Joined: 21 Nov 2010, 05:05
- Location: Saint-Petersburg
- kotbegemot
- Posts: 82
- Joined: 21 Nov 2010, 05:05
- Location: Saint-Petersburg
Well, i've only tested it with SFS PRO 1.6.9 and it works
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
- kotbegemot
- Posts: 82
- Joined: 21 Nov 2010, 05:05
- Location: Saint-Petersburg
Sorry i wrote that on mobile and there i dont have access to the docs xD. It is getCurrentZone() instead of getParentZone()
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
- kotbegemot
- Posts: 82
- Joined: 21 Nov 2010, 05:05
- Location: Saint-Petersburg
Im try this too:
In main Extension:
In caller extension:
Server was restarted and after restart i have this error:
[whoismore.as]: MY EXTENSION = it.gotoandplay.smartfoxserver.extensions.JavascriptExtension@cb396
Error in extension [ whoismore.as ]: TypeError: Cannot find function test. (whoismore.as#3808) Internal: 2231 -- Line number: 2230 in file: whoismore.as
In main Extension:
Code: Select all
var zone = _server.getCurrentZone();
var myExtension = zone.getExtension("miniGameShariki")
trace('MY EXTENSION = ' + myExtension);
myExtension.test()
In caller extension:
Code: Select all
function test() {
trace(' !!!!!!!!!!!!!!!!! TEST !!!!!!!!!!!!!!!!!!!!!!!!!!');
}
Server was restarted and after restart i have this error:
[whoismore.as]: MY EXTENSION = it.gotoandplay.smartfoxserver.extensions.JavascriptExtension@cb396
Error in extension [ whoismore.as ]: TypeError: Cannot find function test. (whoismore.as#3808) Internal: 2231 -- Line number: 2230 in file: whoismore.as
- kotbegemot
- Posts: 82
- Joined: 21 Nov 2010, 05:05
- Location: Saint-Petersburg
I make works only this:
Code: Select all
var zone = _server.getCurrentZone();
var targetExtension = zone.getExtension("miniGameShariki")
var responce = targetExtension.handleInternalRequest("Hello");
trace('RESPONCE: ' + responce);
Code: Select all
function handleInternalRequest(obj)
{
// Simply print the name of the event that was received
//trace("Event received: " + evt.name)
message = String(obj);
if (message.equals("Hello"))
{
return "Hello to you!"
}
else
{
return "Unrecognized message."
}
//var result = String( + " Received ");
return result;
}
Ups It looks like i mixed java and as... sorry... Yes with as it is only possible by the handleInternalRequest. The other way is only for java classes...
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Return to “Server Side Extension Development”
Who is online
Users browsing this forum: No registered users and 59 guests