Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:Creating Instant Messenger in Flash Lite 2.0

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

We do not recommend Flash Lite development on current Nokia devices, and all Flash Lite articles on this wiki have been archived. Flash Lite has been removed from all Nokia Asha and recent Series 40 devices and has limited support on Symbian. Specific information for Nokia Belle is available in Flash Lite on Nokia Browser for Symbian. Specific information for OLD Series 40 and Symbian devices is available in the Flash Lite Developers Library.

Article Metadata
Created: manikantan (15 Apr 2009)
Last edited: hamishwillee (14 Jun 2013)

Instant messengers (IM) are worldwide popular and require no introduction to the common man. In this article, focus is on creating a Jabber based IM with Flash Lite as its client. Flash Lite provides a solid platform to create such applications, with its attractive UI features and networking capabilities.



Jabber is one of the most robust messaging technologies used today. The ubiquitous Google talk uses this technology. eXtensible Messaging and Presence Protocol ([XMPP]) (formerly known as Jabber) is an open, XML-inspired protocol for near real time, extensible instant messaging (IM) and presence information (a.k.a. buddy lists). Unlike most instant messaging protocols, XMPP is based on open standards. Like e-mail, it is an open system where anyone who has a domain name and a suitable Internet connection can run their own Jabber server and talk to users on other servers. The standard server implementations and many clients are also free and open source software. As per the standards, every user has an ID of the format

At one end, we have Jabber based server running. Openfire (previously known as Wildfire Server) is a Jabber/XMPP server written in Java and dual-licensed under both a commercial license and the GNU General Public License. Of the servers listed on the server software list, Openfire implements most of the measured features. Hence, this can be installed and run.

As mentioned earlier, because communication happens primarily through XML sockets, we need to extensively use the same at the client end. In the further headings, focus shall be limited to the client end, which is Flash Lite based.

XIFFIAN Libraries

XIFFIAN (others too exist) is an open source actionscript library that shall be needed for the communication. It has the implementation of the Jabber standard. Hence, importing these libraries is essential in the source is mandatory. In this article, description is based on XIFFIAN libraries.

Use Cases

There are different things that one may imagine when thinking about IMs. The client will need to be authenticated, notified for incoming messages and also support the delivery of an outgoing message to the server in addition to features like Presence management. Below, key use-cases for an IM are described and supported with its code in Actionscript 2.0

Creation of Connection

Creating a connection is the first thing to achieve and is quite simple to do as you follow the code below.

var connection = new XMPPConnection();
connection.username = “Administrator”;
connection.password = “Sample_Password”;
chatRoom = new Room(connection);
chatRoom.roomName = "TestRoom";
conn = connection.connect("flash");
// Parameter includes the Client engine, in our case Flash

Event Handling

Every message from the server arrives as a event into our Client. Hence, we shall need to create event listeners for all cases, we wish to handle.

// Listener setup
var eventHandler = new Object();
connection.addEventListener("outgoingData", eventHandler);
connection.addEventListener("incomingData", eventHandler);
connection.addEventListener("login", eventHandler);
connection.addEventListener("connection", eventHandler);
connection.addEventListener("error", eventHandler);
connection.addEventListener("message", eventHandler);
connection.addEventListener("presence", eventHandler);
eventHandler.handleEvent = function(eventObj) {
switch (eventObj.type) {
case "outgoingData" :
trace("SENT: ";
case "connection" :
statustext.text = "Authenticating ";
case "incomingData" :
trace("RECEIVED: ";
//describing only few important events
case "error" :
if (connection.isActive()) {
trace("WRONG ID OR PWD");
} else {
trace("UNABLE TO CONNECT to "+connection.server);

Creating an event for outgoing and incoming data would be useful during the debugging process, to trace the connection. The event ‘Connection’ arrives when the server is active and is authenticating the user. This arrives just before the result of authentication. The case of ‘error’ event handling is quite obvious from the code. Once, authentication is successful, we get a ‘login’ event. With the arrival of this event, we need to build the buddy list. These are trivial issues and are not focused quite much here.

Handling incoming messages

To receive and process an incoming message, the following code needs to written in the ‘message’ event handling part. Messages are of different types, here the case of Private message is considered.

	case "message" :
var mmm =;
trace("MESSAGE from"+ mmm.from + “CONTENT “ +mmm.body);
// Handle this message by displaying it in the right window.

Sending outgoing messages

To send messages from the client to a buddy, the crux of the code lies in

Msgcontent = “Message content to send“;
chatRoom.sendPrivateMessage(bud_nam, Msgcontent);

Here, bud_name refers to the JabberID (or JID) without the Domain, ie only the username from the

Managing Disconnection

To disconnect the client from the server, the code is quite simple.


There is also a good chance, that the network is very poor and hence the server cannot be reached. In such cases, a frequent checking can be done using the connection.isActive() method.

Maintaining the Buddy List

Managing the buddy list is easily the greatest challenge in the limited screen real estate available to a mobile user. The simplest way is to create a list of buttons that show the name of the buddy. The list of friends is obtained via the Roster variable (in the XIFFIAN library) and arrives immediately after the ‘login’ event arrives. Before joining, in this code, we set our presence to be in ONLINE state.

function loginfn() {
var myRoster:Roster = new Roster(connection);
myRoster.setPresence(null, "Online", 5);
var assk;
assk = chatRoom.join();
trace(“I AM “ +chatRoom.nickname);
// chatRoom contains the list of friends - has to be bound to buddylist container
This page was last modified on 14 June 2013, at 06:30.
20 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.