Forum
>
Smartfox server and Actionscript 3.0
Welcome, Guest

Smartfox server and Actionscript 3.0
Topic Normal Smartfox server and Actionscript 3.0
by pooja on 06/09/2009 14:42

Smartfox Server
SmartFoxServer is a comprehensive and powerful platform for rapidly developing multiuser applications and games with Adobe Flash/Flex/Air, Java, .Net, Unity3D, Apple iPhone and more...
It was developed with simplicity in mind, allowing developers to quickly create any type of multiplayer interactions, from basic chat applications to complex real-time games and MMOs.
If you're using the Actionscript 3.0 API component  you'll use this line :
 import it.gotoandplay.smartfoxserver.*
The first line will always be present in all your "SmartFoxServer" applications as it imports the SmartFoxClient class and its relative helper classes.
 private var sfs:SmartFoxClient   
 private var roomListEvent:SFSEvent
 private const serverIp:String = "127.0.0.1"
 private const serverPort:int = 9339
 private const serverZone:String = "simpleChat"

//SmartFoxClient is the main class in the SmartFoxServer API. This class is responsible for connecting to the server and handling all related events.
//Three simple variables are used to connect to the server: ip, port and zone.
//SFSEvent is the class representing all events dispatched by the Smart Fox Client  instance.
//Establish a connection to SmartFoxServer
public function connect():void
     {
  sfs.connect(serverIp, serverPort)
     }
//Dispatched when the login to a SmartFoxServer zone has been attempted.
   public function onLogin(evt:SFSEvent):void
 {
               var ok:Boolean = evt.params.success
if (!ok)
    {
     trace("Logged Not In");
            }
    else
    {
     trace("Logged In");
                                             }
     }
//Dispatched when a user in the current room updates his/her User Variables
  function onUserVariablesUpdat(evt:SFSEvent):void  
  {
   var room:Room = sfs.getActiveRoom()
                    trace(room);
   trace(evt.params.user.getVariable("cards"));  
  }
 //Dispatched when an error occurs while joining a room.
 public function onJoinRoomError(evt:SFSEvent):void
   {
    //var warning:WarningWindow = PopUpManager.createPopUp(this, WarningWindow, true) as WarningWindow
    //warning.setWarning("Room join error:n" + evt.params.error)
    // Set the selection in the room list component
    //setRoomListSelection(sfs.getActiveRoom()
            )
   //Dispatched when an error occurs during the creation of a room.
   public function onCreateRoomError(evt:SFSEvent):void
   {
    //var warning:WarningWindow = PopUpManager.createPopUp(this, WarningWindow, true) as WarningWindow
    //warning.setWarning("Room creation error:n" + evt.params.error)  
   }
  //Dispatched in response to the connect request. 
 public function onConnection(evt:SFSEvent):void
 { 
    var ok:Boolean = evt.params.success
        if (ok)
    {
     trace("Pass");
     joinZone();
    }
    else
    {
     trace("Fail");
    }
 }
 //Dispatched when the list of rooms available in the current zone is received.
   public function onRoomListUpdate(evt:SFSEvent):void
  {
    roomListEvent = evt
    var rList:Array = roomListEvent.params.roomList as Array
    for each(var r:Room in rList)
    {
     var txt:String = r.getName() + " (" + r.getUserCount() + "/" + r.getMaxUsers() +"/"+r.getId()+ ")"
     trace(txt);
     }
 }
 //Dispatched when a new room is created in the zone where the user is currently logged in.
public function onRoomAdded(evt:SFSEvent):void
   {
    var room:Room = evt.params.room
        // Update view
    var label:String = room.getName() + " (" + room.getUserCount() + "/" + room.getMaxUsers() +    
 "/"+room.getId()+")"
    trace(label);
    
   }
//Dispatched when a room is removed from the zone where the user is currently logged in.
   public function onRoomDeleted(evt:SFSEvent):void
   {
    var room:Room = evt.params.room
     var roomId:int = room.getId()
       }
   // Dispatched when a count change in one room of the zone
   public function onUserCountChange(evt:SFSEvent):void
   {
    var r:Room = evt.params.room as Room
    var id:int = r.getId()
    // Cycle through all rooms in the list and find the one that changed
    /*for each (var o:Object in roomList.dataProvider)
    {
     if (o.data == id)
     {
       o.label = r.getName() + " (" + r.getUserCount() + "/" + r.getMaxUsers() + ")"
      break
     }
    }
        roomList.invalidateList()*/
   }
  // Handle a public message
   public function onPublicMessage(evt:SFSEvent):void
   {
    var message:String = evt.params.message
    var sender:User = evt.params.sender
        //ta_chat.htmlText += "<b>[" + sender.getName() + "]:</b> " + message +"<br>"
    //ta_chat.verticalScrollPosition = ta_chat.maxVerticalScrollPosition
   }
 //Handle a private message
  public function onPrivateMessage(evt:SFSEvent):void
   {
    var message:String = evt.params.message
    var sender:User = evt.params.sender
    //ta_chat.htmlText += "<b><font color='#550000'>[PM - " + sender.getName() + "]:</font></b> " + message +"<br>"
   }
  // Dispatched when new user  enters the current room
   public function onUserEnterRoom(evt:SFSEvent):void
   {
    var roomId:int = evt.params.room as int
    var user:User = evt.params.user as User
    //var provider:ArrayCollection = userList.dataProvider as ArrayCollection
           //provider.addItem( {label:user.getName(), data:user.getId()} )
    //provider.refresh()    
        //userList.invalidateList()
   }  
 //Dispatched when a user leaves the current room.
   public function onUserLeaveRoom(evt:SFSEvent):void
   {
    var roomId:int = evt.params.roomId as int
    var userId:int = evt.params.userId as int
                }
   
 // Dispatched when Connection is lost
   public function onConnectionLost(evt:SFSEvent):void
   {
    //viewstack.selectedChild = view_logout
   }
   
     public function invokeExtension(dat:String)
  {
   var o:Object=new Object();
      o.name=dat;
     sfs.sendXtMessage("Game", "GameE", o)
   }
 
 }
}