4.2 API Overview
The SmartFoxServer Client API provide a set of high level classes that interact asynchronously with the server with a simple event-based callback system. Additionally the API allow using native ActionScript objects for sending and receiving data to and from the server.
The SmartFoxClient class is the main entry point of the API, where you register for server notifications and call methods for logging in, joining rooms, sending messages etc...
» Asynchronous programming
By working with Flash/Flex you should already be familiar with asynchronous programming.
Basically each time you load variables, images or external movie clips, you
have to register a callback function that will handle the completion of the task, which may happen at any momement depening on the location of the resource.
This same approach is also at the basis of all multi-user / multi-player applications.
For every request that you send to the server you will need a corresponding event handler that will take care of the asynchronous response coming from the server.
Here's a very simple example of how it works (ActionScript 2.0):
// Import the API classes import it.gotoandplay.smartfoxserver.*
// Create an instance of the SmartFoxClient class var sfs:SmartFoxClient = new SmartFoxClient()
// Attempt a connection to the server sfs.connect("127.0.0.1", 9339) sfs.onConnection = function(success:Boolean):Void { if (success) { trace("Great! Connected successfully!") } else { trace("An error occurred, could not connect!") } }
» Importing and using the SmartFoxClient class
In order to use the SmartFoxClient class you will need
to tell Flash to include it in your current code. This is usually done by adding
in the very first line of your code an ActionScript command, based on which ActionScript
version you're using in your project.
For Flash MX and MX2004 using ActionScript 1.0 be sure to have this line as the
very first one in your code:
#include "SmartFoxClient.as"
For Flash and Flex using ActionScript 2.0 and 3.0, use this line instead:
import it.gotoandplay.smartfoxserver.*
doc index |