Call function from another extension in same zone as1

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

Moderators: Lapo, Bax

Post Reply
kotbegemot
Posts: 82
Joined: 21 Nov 2010, 05:05
Location: Saint-Petersburg

Call function from another extension in same zone as1

Post by kotbegemot »

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

Post by rjgtav »

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

Post by kotbegemot »

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

Post by kotbegemot »

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

Post by rjgtav »

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

Post by kotbegemot »

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

Post by rjgtav »

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

Post by kotbegemot »

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

Post by kotbegemot »

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

Post by rjgtav »

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.
Post Reply