Call function from another extension in same zone as1

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

User avatar
kotbegemot
Posts: 82
Joined: 21 Nov 2010, 05:05
Location: Saint-Petersburg

Call function from another extension in same zone as1

Postby kotbegemot » 14 Jul 2011, 09:34

Is it possible to call function from one extension to another in one zone ?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 14 Jul 2011, 10:00

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

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.
User avatar
kotbegemot
Posts: 82
Joined: 21 Nov 2010, 05:05
Location: Saint-Petersburg

Postby kotbegemot » 14 Jul 2011, 10:06

VERY VERY VERY THANKS :) !!!!
User avatar
kotbegemot
Posts: 82
Joined: 21 Nov 2010, 05:05
Location: Saint-Petersburg

Postby kotbegemot » 14 Jul 2011, 11:09

Are you sure what its must be work on 1.6 SFS ?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 14 Jul 2011, 11:28

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.
User avatar
kotbegemot
Posts: 82
Joined: 21 Nov 2010, 05:05
Location: Saint-Petersburg

Postby kotbegemot » 14 Jul 2011, 12:04

But SFS 1.6.9 have no getParentZone() method ....

Its method have only SFS 2x
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 14 Jul 2011, 12:38

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.
User avatar
kotbegemot
Posts: 82
Joined: 21 Nov 2010, 05:05
Location: Saint-Petersburg

Postby kotbegemot » 14 Jul 2011, 12:45

Im try this too:

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
User avatar
kotbegemot
Posts: 82
Joined: 21 Nov 2010, 05:05
Location: Saint-Petersburg

Postby kotbegemot » 14 Jul 2011, 13:20

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;
}
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 14 Jul 2011, 14:11

Ups :oops: 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.

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 59 guests