How do you encapsulate extension logic?

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

thegreenbit
Posts: 9
Joined: 09 Apr 2008, 22:29
Contact:

How do you encapsulate extension logic?

Postby thegreenbit » 25 Apr 2008, 00:56

Hi,

All the extension files I see in sfsExtension folder have their logic written in the same file.

Is there a way to encapsulate server logic in classes?

I tried importing my classes into the "extension".as file with the four core functions but I was getting an syntax error from SFS complaining about the import.

Did I miss something obvious?

Thanks.
thegreenbit
Posts: 9
Joined: 09 Apr 2008, 22:29
Contact:

Postby thegreenbit » 28 Apr 2008, 16:42

bump..

Help please.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Apr 2008, 07:49

Yes, you can make classes, you can declare them in external files and import them into your main extension file.

By default each extension file should be located under sfsExtensions/ or any subfolder created under that path.

You could have this scenario:
sfsExtensions/classes/myClasses1.as
sfsExtensions/classes/myClasses2.as
sfsExtensions/classes/MainExtension.as

in MainExtension.as you put this code at the beginning:

Code: Select all

#include "classes/myClasses1.as"
#include "classes/myClasses2.as"
...
rest of the code
...
Lapo
--
gotoAndPlay()
...addicted to flash games
thegreenbit
Posts: 9
Joined: 09 Apr 2008, 22:29
Contact:

Postby thegreenbit » 29 Apr 2008, 16:59

Hi Lapo,

I tried using include to import my own classes, but the SFS console complains about the keyword "class". It says that it is a reserve word and threw an error.

If you want to look at my test code, here it is:

Code: Select all

class TestClass
{
   function TestClass()
   {
      trace("contructing testclass");
   }   
   
}
BenV
Posts: 7
Joined: 17 May 2007, 21:22

Postby BenV » 29 Apr 2008, 23:18

Classes are not supported like that in AS1/Javascript. Here is a good tutorial on using classes that you can follow:

http://www.xml.com/pub/a/2006/06/07/obj ... cript.html
mstram
Posts: 17
Joined: 06 Jun 2014, 23:46

Re:

Postby mstram » 11 Jun 2014, 06:36

BenV wrote:Classes are not supported like that in AS1/Javascript. Here is a good tutorial on using classes that you can follow:

http://www.xml.com/pub/a/2006/06/07/obj ... cript.html


Is this still the case ?

Are sfsExtensions still AS1 ?

(it seems to be, as I just tried the above class example and got the same error).

Mike
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How do you encapsulate extension logic?

Postby Lapo » 11 Jun 2014, 07:57

If you're using SmartFoxServer PRO, as I presume, then yes you can use AS/JS or Python or Java.
Lapo

--

gotoAndPlay()

...addicted to flash games
mstram
Posts: 17
Joined: 06 Jun 2014, 23:46

Re: How do you encapsulate extension logic?

Postby mstram » 11 Jun 2014, 09:34

Lapo wrote:If you're using SmartFoxServer PRO, as I presume, then yes you can use AS/JS or Python or Java.


Yes I'm using the current Pro server.

What level of AS is supported by the server-extensions?

Is the "external class file / syntax" supported ?

thx

Mike
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How do you encapsulate extension logic?

Postby Lapo » 11 Jun 2014, 09:50

It is compatible with ECMA 262 specs. Or Javascript in other words.
So it's not like Actionscript 3.

If you wish to use something like AS3 then I'd highly recommend using straight Java. AS3 is heavily "inspired" by Java. Same OOP paradigm, syntax etc... if you are familiar with AS3 moving to Java is a no brainer, plus you'll find a more rich set of API.

Back to the AS1/JS question you can import other source files using the "include" directive. You can learn all the details by taking a look at Section 7 of the SFS PRO docs: http://www.smartfoxserver.com/docs/1x/

If you haven't started developing yet, my suggestion is to also take a look at SFS2X, which is more recent and offers a ton of new features.
A feature comparison is provided here:

http://www.smartfoxserver.com/products
Lapo

--

gotoAndPlay()

...addicted to flash games
mstram
Posts: 17
Joined: 06 Jun 2014, 23:46

Re: How do you encapsulate extension logic?

Postby mstram » 11 Jun 2014, 12:11

Actually I tried SFS2X before Pro.

I ran into into a bunch of problems with it, and so tried Pro.

It's a shame that that javascript extensions aren't in SFS2x.

I'll probably "bite the bullet" and try to get the Java extensions working.

I find setting up Java / Eclipse, and working with Java a royal pain in the #%#. All the "overhead", importing etc etc

**** I just read / followed your excellent tutorial on setting up / compiling an extension in Eclipse, and all went smoothly (at least the compile / export process)

Thanks for the great job on writing that doc (and the rest of the docs too ! :)
***

In contrast the AS/JS extensions have been a breeze to work with (no compiling /Eclipse etc, save / reload extension, nice extension monitoring in the PRO admin tool).

Btw is there an extension monitor in SFS2X ?

I see a 'tris' zone under the admin tool / zone config, but it doesn't show up under the zone monitor tab (just have "BasicExamples" and "BattleFarm" there)

I'm revisiting SFS2X, now.

I'll make another thread / bug report of what I'm finding

Mike

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 33 guests