BeamServer Flash Component

Introduction

The client side BeamServer component for Flash contains two classes: BSEvent and BSClent, this both are located in BeamServerClient.swc library, which is contained in BeamServer basic package. BeamServerClient.swc must be installed inside Flash and imported into the library in order to this classes are visible inside our application.

BSEvent class

BSEvent class extends flash.events.Event and contains a parameter named "Result", where all data associated with the BeamServer events are located.

The following Actionscript code shows the use of the BSEvent class:

var client: BSClient = new BSClient();

function NodeAddedHandler(event: BSEvent)
{
             var name: String = event.Result.name;
             var nodeId: int = event.Result.nodeId;
             ...
}

client.addEventListener(“OnNodeAdded”, NodeAddedHandler);

BSClient class

This class is the core of any Flash application using BeamServer. It contains all the necessary functionality for connect with BeamServer, move through nodes, create and destroy nodes, do subscriptions, modify attributes and access to all functionalities of BeamServer. BSClient class also generates all events associated with the server.

The following methods are available in BSClient class:

ConnectToServer(ip:String, port:uint, pfile:String, pport:int)

Connects to the BeamServer server associated to the IP address and the specified port.

If successful an OnConnect event is dispatched, otherwise an OnError event is dispatched.

ip: String  - Server IP address.
port: uint  - Server port number.
pfile: String – Policy file, ignored if void.
pport: int – HTTP port of the server where policy file is located. 80 by default.

CloseConnection()

Closes the connection with the server.

When the connection is closed an OnDisconnect event is dispatched.

GetId():int

Output: Returns the unique ID of the node that represents our connection inside the server.

LoginToServer(user:String,pass:String)

Sends a login request to the server with the user name and password specified. It is esential to do this before any other operation on the server.

Once the request has been procesed by the server an OnLogin event is received, indicating the success or failure of the proccess.

user: String – User name.
pass: String – Password.

JoinNode(nodeId:uint,user:String,pass:String)

This function makes our connection node join to the node list of the specified node.

nodeId: uint –Unique ID of the node we want to join.
user: String – User name.
pass: String – Password.

SubscribeToNode(nodeId:uint)

This does a subscription to the node with the specified ID. After this we will receive events associated to any change performed in the node.

nodeId: uint – Unique ID of the node we want to subscribe to.

UnsubscribeFromNode(nodeId:uint)

Cancels the subscription with the node with the specified ID.

nodeId: uint – Unique ID of the node we want to unsubscribe from.

SendObject(nodeId:uint,data:Object)

Sends data to the node with the specified ID. Any data type can be sent but there are some compatibility issues to take into account (See the end of this document).

nodeId: uint –Unique ID of the node we want to send data to.
data: Object – Data.

LeaveNode(nodeId:uint)

Removes our node from the node list of the specified node.

nodeId:  uint – Unique ID of the node we want to exit from.

CreateNode(nodeId:uint,name:String,param:Object)

Creates a new node with the name and attributes specified, and adds it to the node list of the node with the specified ID.

nodeId: uint – Unique ID of the parent node.
name: String –New node name.
param: Object – Default attributes for the new node.

DestroyNode(nodeId:uint)

Destroys the node with the specified ID.

nodeId:uint – The node ID of the node we want to destroy.

SetAttribute(nodeId:uint,name:String,value:Object)

Changes the value of the attribute with the specified name in the node with the specified ID. If the attribute doesn't exists, a new attribute is created, if the value is null, the attribute is destroyed.

nodeId: uint – Unique ID of the node.
name: String – Name of the attribute.
value: Object – New attribute value.

SetChildAttribute(nodeId:uint,childId:uint,name:String,value:Object)

Changes the value of the attribute with the specified name in the node with the specified ID (childId), inside the node list of the node with the specified ID (nodeId). If the attribute doesn't exists, a new attribute is created, if the value is null, the attribute is destroyed.

nodeId: uint – Unique ID of the parent node.
childId: uint – Unique ID of the node which owns the attribute.
name: String – Attribute name.
value: Object – Attribute new value.

FindNodeByName(name:String)

Sends a search request to look for a node by its name. The search context is global, searching in all the server structure. This method will generate an OnNodeFound event.

name: String - Node name.

Events generated by BSClient and content of the parameter "Result"

OnConnect  
OnDisconnect  
OnError  
OnLogin

sender:uint - Event origin node.
result:String - Request result.

nodeId:uint - My own ID, if success.

OnJoinNode

sender:uint - Event origin node.
success:String - Success or failure of the operation.

nodeId:uint - My own ID.
OnNodeAdded

sender:uint - Event origin node.
nodeId:uint - New node Id.
name:String - New node name.

param:Object - New node Attributes.
OnNodeRemoved

sender:uint - Event origin node.

nodeId:uint - Removed node ID.
OnChildAttributeUpdated

sender:uint - Event origin node.
nodeId:uint - Modified node ID.
name:String - Attribute name.

value:Object - New attribute value.
OnAttributeUpdated

sender:uint - Event origin node.
name:String - Attribute name.

value:Object - New attribute value.
OnObjectReceived

sender:uint - Event origin node.
codec:uint - Data type.

data:Object - Received data.
OnLeaveNode sender:uint - Event origin node.
OnNodeDestroyed

sender:uint - Event origin node.

nodeId:uint - Destroyed node ID.
OnNodeFound

sender:uint - Event origin node.

found:boolean - True or False.

nodeId:uint - Node ID if found, 0 otherwise.

Flash component installation

  1. Close Flash
  2. Put the BeamServerClient.swc file in the following folder:
  1. Windows: C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Components
  2. Macintosh: Macintosh HD/Applications/Adobe Flash CS3/Configuration/Components
  1. Start Flash
  2. Open the components window in order to check if it is succesfully installed.

The Flash installation folders may change with different product versions, OS languages and user preferences.

Component use

Once we have put the component in the correct folder and we have checked it is on the component Flash window we can use it.

Drag the BeamServer client component from the components window to the library window and add the following code lines in your code:

import BeamServer.BSClient;
import BeamServer.BSEvent;

we can access this two classes now.

Client-Server data transference

Communication between the Flash client application and BeamServer is done using the "SendObject" and "OnObjectReceived" methods.

Virtually any data type can be transferred, however we should take into account some platform compatibility issues.

.NET type                                               Flash type