SmartFoxServer PRO bits part 2

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

Moderators: Lapo, Bax

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

SmartFoxServer PRO bits part 2

Postby Lapo » 02 Jul 2005, 13:20

Hello,
while we're finishing the final bits of SmartFoxServer PRO, we'd like to share some previews of what you will find with the server side extensions.

We mentioned in the last "teaser" that SFS PRO comes with an Actionscript framework for writing your server side logic.
For more advanced programmers we have an interesting extre feature that I am quite sure you will like: Java objects in Actionscript! 8)

What ? :shock: :?:

Yep! Within your Actionscript code you will be able to create instances of any Java class from the Java2 framework or any custom library and you will be able to access them as if they were normal objects.

An example? Here we go:

Code: Select all

  var list = new java.util.LinkedList()
   
   for (var i = 0; i < 10; i++)
   {
                list.add("Item " + i)
   }
   
   // Use a Java iterator to cycle through the list
   for (var it = list.iterator(); it.hasNext();)
   {
                trace(it.next())
   }


As you can see a LinkedList from the java.util package is created and filled with 10 items. Then we use an Iterator to cycle through it and output its values.

Here follows another, more advanced, example. In this case we use the NanoXML library, an excellent, super fast and easy to use XML parser. The parser is not provided with the Java2 standard classes but we can use them by adding them to the classpath and using the Packages object from Actionscript to access it .

( Check NanoXML here )

Code: Select all

function init()
{
   // Create a reference to the Java package
   // This help us building new objects from the nanoxml package.
   // Instead of typing the fully qualified Class name we'll just use:
   //
   // var obj = new nanoxml.SomeObject()
   nanoxml = Packages.net.n3.nanoxml

      
   readTheXmlFile()
}


/*
* Read and parse the XML file
*/
function readTheXmlFile()
{
   // Setup the xml parser object
   var xmlParser = nanoxml.XMLParserFactory.createDefaultXMLParser()
   
   // This is the XML Reader:
   // You can use a fileReader, to read the XML from a file
   // or the StringReader, to read the XML from a string
   var xmlReader = nanoxml.StdXMLReader.fileReader("sfsExtensions/data/books.xml")
   
   // Assign the reader to the parser
   xmlParser.setReader(xmlReader)
   
   // Finally parse the XML
   var xmlDoc = xmlParser.parse()
   
   // Get the tag called <collectionName></collectionName>
   var node = xmlDoc.getFirstChildNamed("collectionName")
   trace("Collection Name: " + node.getContent())
   
   // Get the tag called <collectionOwner></collectionOwner>
   var node = xmlDoc.getFirstChildNamed("collectionOwner")
   trace("Collection Owner: " + node.getContent() + newline)
   
   // Get the tag called <collectionOwner></collectionOwner>
        var node = xmlDoc.getFirstChildNamed("bookList")
   
   // book is a java.util.Enumeration object
   var books = node.enumerateChildren()
   
   // Cycle through each element in the Enumeration
   //
   while (books.hasMoreElements())
   {
      var book = books.nextElement()
      
      trace("Title    : " + book.getAttribute("title", ""))
      trace("Author   : " + book.getAttribute("author", "unknown"))
      trace("Year     : " + book.getAttribute("year", "unknown"))
      trace("Publisher: " + book.getAttribute("publisher", "unknown"))
      trace("-------------------------------------")
   }
}


The XML file that is being read looks like this:

Code: Select all

<bookCollection>

   <!-- Title and collection name -->
   <collectionName>My Tech Book Collection</collectionName>
   <collectionOwner>Lapo</collectionOwner>
   
   <!-- The list of books goes here -->
   <bookList>
      <book title="Head First Design Patterns"
         author="Freeman, Freeman"
         year="2004"
         publisher="O'Reilly"
      />
      
      <book title="Thinking in Java"
         author="B.Eckel"
         year="2003"
         publisher="Prentice Hall"
      />
      
      <book title="C++ From ground up"
         author="H.Schildt"
         year="2004"
         publisher="McGraw-Hill Osborne Media"
      />
      
      <book title="Python in a Nuthsell"
         author="A.Martelli"
         year="2003"
         publisher="O'Reilly"
      />
      
      <book title="C# Cookbook"
         author="Teilhet, Hilyard"
         year="2003"
         publisher="O'Reilly"
      />
   </bookList>
   
</bookCollection>


The ability to incorporate native Java classes in Actionscript will expand the potential of server side extensions and allow developers to create extremely complex and feature-rich applications on the server side.

Lapo
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 32 guests