Main Page | Packages | Class Tree | Index

it.gotoandplay.smartfoxbits.bits

class Connector

MovieClip
  |
  +--it.gotoandplay.smartfoxbits.bits.Connector


class Connector
extends MovieClip

The Connector class provides methods and properties to control the SmartFoxBits' Connector component behavior at author-time and run-time.

The SmartFoxBits' Connector component lets you establish a connection to a SmartFoxServer instance running on a specified IP address and TCP port.

The Connector has built-in led and label to display the connection status. The label can be customized by setting the status message, its placement (to the led's right or left) and the distance from the led. You can also customize the label text style accessing the Label component through the statusLabel property.
The default led can be substituted with a custom led from your application library; just set the linkage of your custom led movieclip to: it.gotoandplay.smartfoxbits.bits.assets.LedIcon. To display all the connection statuses properly, the custom led movieclip must have the following structure:

NOTE 1: use the same frame labels (case-sensitive).
NOTE 2: add a stop() action in each frame.

Usage:
Drag & drop the Connector component onto the stage and set its properties in the Property Inspector at author-time, or attach it at run-time using actionscript.

If you use this component in conjunction with other SmartFoxBits, make sure it's instantiated before the other components. This is required because the other components register to the Connector's event handler in order to communicate with SmartFoxServer.
To achieve this you should place the Connector on a frame and the other components on the following frame(s). If you need to put all the SmartFoxBits on a single frame, just make sure that the Connector is on the lowest layer of the timeline, and set the "Load order" option in the Flash Publish Settings to "Bottom up".

To make the component connect to SmartFoxServer as soon as it is instantiated at run-time, set the auto-connect property to true.


Author:

Version:
1.0.0 - First release.

Since:
SmartFoxBits v1.0

Example:
To instantiate the Connector at run-time, make sure it's contained in your library and write the following:
import it.gotoandplay.smartfoxbits.bits.Connector
 
var connector_mc:Connector = Connector(attachMovie("Connector", "connector_mc", 0))
connector_mc.connect()

NOTE 1: importing the it.gotoandplay.smartfoxbits.bits.Connector class and casting the Connector's movieclip to it is useful if you intend to use a development tool having code-completion features. Otherwise this is enough:

var connector_mc = attachMovie("Connector", "connector_mc", 0)
NOTE 2: in the following examples connector_mc represents the Connector instance name.

See also:


Property Summary

public
autoConnect: Boolean (read, write)
Enable/disable the Connector's "auto-connect" feature.

public
connectedMessage: String (read, write)
The message displayed by the Connector's label after a successful connection to SmartFoxServer.

public
connectingMessage: String (read, write)
The message displayed by the Connector's label during connection attempt.

public
connection: SmartFoxClient (read-only)
A reference to the SmartFoxClient class instance.

public
connectionFailedMessage: String (read, write)
The message displayed by the Connector's label if the connection attempt failed.

public
connectionLostMessage: String (read, write)
The message displayed by the Connector's label if the connection with SmartFoxServer was lost.

public
debug: Boolean (read, write)
Enable/disable the Connector's debugging feature.

public
height: Number (read, write)
The height of the Connector component on the stage, in pixels.

public
isConnected: Boolean (read-only)
The current connection status.

public
labelPlacement: String (read, write)
The position of the Connector's label, to the right or to the left of the led.

public
notConnectedMessage: String (read, write)
The message displayed by the Connector's label before attempting to connect to SmartFoxServer.

public
serverIpAddress: String (read, write)
The IP address of the server on which the SmartFoxServer instance is running.

public
serverPort: Number (read, write)
The TCP port of the server on which the SmartFoxServer instance is running.

public
spacing: Number (read, write)
The number of pixels between the Connector's label and led.

public
statusLabel: Label (read-only)
A reference to the Connector's status label.

public
width: Number (read, write)
The width of the Connector component on the stage, in pixels.

Constructor


Connector ( )
Connector class constructor. Initializes the component at author-time.

Method Summary

public
addEventListener ( type: String, listener: Function ): Void
Register a listener function in order to receive notification of a SmartFoxServer event.

public
connect ( ): Void
Establish a connection with SmartFoxServer.

public
refreshView ( ): Void
Refresh the Connector's view.

public
removeEventListener ( type: String, listener: Function ): Void
Remove a listener from the Connector's event dispatcher, to stop receiving notification of an event.



Property Documentation

autoConnect

public autoConnect: Boolean (read, write)
Enable/disable the Connector's "auto-connect" feature.

When the "auto-connect" feature is turned on, the Connector sets up the communication with SmartFoxServer as soon as it's instantiated on the stage. Otherwise the connection must be started manually calling the connect method.

Usage:
To enable auto-connect:
connector_mc.autoConnect = true

See also:

connectedMessage

public connectedMessage: String (read, write)
The message displayed by the Connector's label after a successful connection to SmartFoxServer.

Usage:
To set the "connection successful" message:
connector_mc.connectedMessage = "You are connect to SmartFoxServer!"

See also:

connectingMessage

public connectingMessage: String (read, write)
The message displayed by the Connector's label during connection attempt.

Usage:
To set the "connecting" message:
connector_mc.connectingMessage = "Trying to connect to server..."

See also:

connection

public connection: SmartFoxClient (read-only)
A reference to the SmartFoxClient class instance.

This reference allows you to invoke API methods to send server commands and requests, and handle events sent by the server.
You can use this reference if you need to set up a custom dialogue with the server, whithout using other SmartFoxBits components' event dispatchers.

Usage:
To get a reference to the SmartFoxClient instance:
import it.gotoandplay.smartfoxserver.*
 
var smartFox:SmartFoxClient = connector_mc.connection
var zone:String = "simpleChat"
var myUserName:String = "Jack"
 
smartFox.login(zone, myUserName) // Login me into "simpleChat" zone

NOTE: importing the it.gotoandplay.smartfoxserver package is useful if you intend to use a development tool having code-completion features. Otherwise getting the connection in this way is enough: var smartFox = connector_mc.connection.

connectionFailedMessage

public connectionFailedMessage: String (read, write)
The message displayed by the Connector's label if the connection attempt failed.

Usage:
To set the "connection failed" message:
connector_mc.connectionFailedMessage = "Warning: connection to SmartFoxServer failed"

See also:

connectionLostMessage

public connectionLostMessage: String (read, write)
The message displayed by the Connector's label if the connection with SmartFoxServer was lost.

Usage:
To set the "connection lost" message:
connector_mc.connectionLostMessage = "Warning: connection to SmartFoxServer lost"

See also:

debug

public debug: Boolean (read, write)
Enable/disable the Connector's debugging feature.

When the debug is turned on, the messages exchanged with SmartFoxServer by all the SmartFoxBits components are traced in the Flash Output panel during the movie testing.

Usage:
To enable debugging:
connector_mc.debug = true

See also:

height

public height: Number (read, write)
The height of the Connector component on the stage, in pixels.

Use this property instead of _height to mantain the led's aspect ratio.
This property doesn't affect the aspect of the component on the stage: the led and the label are vertically centered on respect of the given height.

Usage:
To set the component height:
connector_mc.height = 50

See also:

isConnected

public isConnected: Boolean (read-only)
The current connection status.

Usage:
To check the connection status:
if (connector_mc.isConnected)
{
	trace("Connection to SmartFoxServer successful!")
}

Value:
true if the Connector component succesfully connected to SmartFoxServer.
false if the Connector isn't connected to SmartFoxServer, or if connection was lost.

See also:

labelPlacement

public labelPlacement: String (read, write)
The position of the Connector's label, to the right or to the left of the led.

Whatever the placement of the label is, the displayed text is always aligned so that it starts or ends at the distance from the led specified in the property.
So, if the label is placed to the left of the led, then the text is right-aligned inside its textbox.

Usage:
To set the label placement:
connector_mc.labelPlacement = "left"

See also:

notConnectedMessage

public notConnectedMessage: String (read, write)
The message displayed by the Connector's label before attempting to connect to SmartFoxServer.

Usage:
To set the "not connected" message:
connector_mc.notConnectedMessage = "Not yet connected"

See also:

serverIpAddress

public serverIpAddress: String (read, write)
The IP address of the server on which the SmartFoxServer instance is running.

Usage:
To set the server IP address:
connector_mc.serverIpAddress = "127.0.0.1"

To retrieve the address:

trace(connector_mc.serverIpAddress) // Traces the SmartFoxServer connection IP address

See also:

serverPort

public serverPort: Number (read, write)
The TCP port of the server on which the SmartFoxServer instance is running.

Usage:
To set the server port:
connector_mc.serverPort = 9339

To retrieve the port:

trace(connector_mc.serverPort) // Traces the SmartFoxServer connection TCP port

See also:

spacing

public spacing: Number (read, write)
The number of pixels between the Connector's label and led.

Usage:
To set the spacing:
connector_mc.spacing = 10

See also:

statusLabel

public statusLabel: Label (read-only)
A reference to the Connector's status label.

This reference allows you to take control over the status Label mCOM component, to set its properties (for example text styling). Please notice that if you change the component height, you have to call the refreshView method to rearrange the Connector's view accordingly.
Check the mCOM Flash components documentation for further details.

Usage:
To access the status Label component:
import com.metaliq.controls.Label
 
var lb:Label = connector_mc.messageLabel
lb.setInstanceStyle("fontColor", 0xCC0000)

See also:
com.metaliq.controls.Label, SmartFoxBits and the mCOM Flash components

width

public width: Number (read, write)
The width of the Connector component on the stage, in pixels.

Use this property instead of _width to mantain the led's aspect ratio and resize the label's textbox accordingly. If the label's text exceeds the width value, clipping occurs.

Usage:
To set the component width:
connector_mc.width = 300

See also:


Constructor Documentation

Connector

function Connector()
Connector class constructor. Initializes the component at author-time.


Method Documentation

addEventListener

public function addEventListener(type: String,
 listener: Function): Void
Register a listener function in order to receive notification of a SmartFoxServer event.

You can register to events fired by SmartFoxServer using the Connector, in case you need to be notified to execute additional code for your purposes. Using the Connector's addEventListener method instead of the standard way of registering to SmartFoxServer events (for example: smartFoxClientInstance.onConnection = Delegate.create(this, myEventListener)) lets you have different listeners for the same events: this is useful in case you need to build a modular architecture. As all SmartFoxBits componentents rely on this concept, if you plan to use the Connector in conjunction with other SmartFoxBits components, it's mandatory to use this method to listen to events.

See the it.gotoandplay.smartfoxbits.events.SFSEvent class for the event types dispatched by the Connector and for details on the parameters contained in the event object.

If you no longer need an event listener, remove it by calling the removeEventListener method.

NOTE: use the Delegate.create(listenerFunctionName) method when registering a listener, to keep right scope in your application.

Usage:
To register to an event:
import it.gotoandplay.smartfoxbits.events.*
import mx.utils.Delegate
 
connector_mc.addEventListener(SFSEvent.onConnection, Delegate.create(this, myListener))
 
private function myListener(evt:SFSEvent):Void
{
	trace("Got the event!")
	trace("Event type: " + evt.type)
	trace("Event target: " + evt.target)
	trace("Additional parameters:")
 
	for (var i in evt.params)
		trace("\t" + i + " -> " + evt.params[i])
}

Parameters:
type
The SmartFoxServer's event type you want to be notified of.
listener
The listener function in your application that processes the event. This function must accept an SFSEvent object as its only parameter and must return nothing, as in the example above.
See also:

connect

public function connect(): Void
Establish a connection with SmartFoxServer.

When this method is called, the Connector establishes a communication with SmartFoxServer using the specified IP address and TCP port. If the auto-connect feature is turned on, this method is called by the component itself as soon as it's instantiated at run-time.

Usage:
To establish a connection to SmartFoxServer manually:
connector_mc.connect()

See also:

refreshView

public function refreshView(): Void
Refresh the Connector's view.

If you change the size of the Connector's inner components, you have to call this method to rearrange the Connector's view accordingly.

removeEventListener

public function removeEventListener(type: String,
 listener: Function): Void
Remove a listener from the Connector's event dispatcher, to stop receiving notification of an event.

Usage:
To remove a listener:
connector_mc.removeEventListener(SFSEvent.onConnection, myListener)

NOTE: the Delegate.create(listenerFunctionName) is not required to remove a listener.

Parameters:
type
The SmartFoxServer's event type you registered your listener to.
listener
The listener function to remove.
See also:


The documentation was generated from the following file: