Elisabetta with a bag
One particular lady in Italy never goes unnoticed, Elisabetta Canalis.

XIFF chat - Part 2: Roster

This example lists the people in your contacts (roster) and enables sending messages to each of them. In order to understand how XMPP works, I suggest reading RFC3921.

package
{
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    import flash.system.Security;
    import flash.ui.Keyboard;

    import org.igniterealtime.xiff.conference.*;
    import org.igniterealtime.xiff.core.*;
    import org.igniterealtime.xiff.data.*;
    import org.igniterealtime.xiff.data.disco.*;
    import org.igniterealtime.xiff.data.im.*;
    import org.igniterealtime.xiff.events.*;
    import org.igniterealtime.xiff.exception.*;
    import org.igniterealtime.xiff.im.*;
    import org.igniterealtime.xiff.util.*;

    [SWF(backgroundColor = '0x5B5B5B', frameRate = '33', width = '600', height = '400')]

    /**
     * @see http://paazmaya.fi/xiff-chat-part-2-roster
     */
    public class XIFFstep2 extends Sprite
    {
        private const SERVER:String = "192.168.1.37";
        private const PORT:Number = 5222;
        private const USERNAME:String = "flasher";
        private const PASSWORD:String = "flasher";
        private const RESOURCE_NAME:String = "flashPlayer";
        private const CHECK_POLICY:Boolean = true;

        private var _connection:XMPPSocketConnection;
        private var _roster:Roster;

        private var _keepAlive:Timer;
        private var _people:Dictionary;
        private var _outputField:TextField;
        private var _inputField:TextField;
        private var _recipientField:TextField;
        private var _rosterCont:Sprite;
        private var _chattingWith:EscapedJID;

        public function XIFFstep2()
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;

            loaderInfo.addEventListener(Event.INIT, onInit);
        }

        private function onInit(event:Event):void
        {
            if (CHECK_POLICY)
            {
                Security.loadPolicyFile("xmlsocket://" + SERVER + ":5229");
            }
            createElements();

            initChat();
        }

        private function createElements():void
        {
            _outputField = new TextField();
            _outputField.background = true;
            _outputField.backgroundColor = 0xF4F4F4;
            _outputField.textColor = 0x042444;
            _outputField.mouseWheelEnabled = true;
            _outputField.multiline = true;
            _outputField.width = stage.stageWidth - 130;
            _outputField.height = stage.stageHeight - 54;
            _outputField.x = 129;
            _outputField.y = 22;
            addChild(_outputField);

            _inputField = new TextField();
            _inputField.background = true;
            _inputField.backgroundColor = 0xF4F4F4;
            _inputField.textColor = 0x042444;
            _inputField.type = TextFieldType.INPUT;
            _inputField.width = stage.stageWidth - 2;
            _inputField.height = 29;
            _inputField.x = 1;
            _inputField.y = stage.stageHeight - 30;
            _inputField.maxChars = 40;
            _inputField.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
            addChild(_inputField);

            _recipientField = new TextField();
            _recipientField.background = true;
            _recipientField.backgroundColor = 0xF4F4F4;
            _recipientField.textColor = 0x042444;
            _recipientField.width = stage.stageWidth - 130;
            _recipientField.height = 20;
            _recipientField.x = 129;
            _recipientField.y = 1;
            addChild(_recipientField);

            _rosterCont = new Sprite();
            addChild(_rosterCont);
        }

        private function messageSend():void
        {
            var txt:String = _inputField.text;
            var msg:Message = new Message(_chattingWith, null, txt, null, Message.CHAT_TYPE);
            if (_connection.isLoggedIn())
            {
                _connection.send(msg);
                _inputField.text = "";
                addMessage(_connection.jid.escaped, txt);
            }
        }

        private function initChat():void
        {
            _connection = new XMPPSocketConnection();
            _connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, onXiffError);
            _connection.addEventListener(IncomingDataEvent.INCOMING_DATA, onIncomingData);
            _connection.addEventListener(LoginEvent.LOGIN, onLogin);
            _connection.addEventListener(MessageEvent.MESSAGE, onMessage);
            _connection.addEventListener(OutgoingDataEvent.OUTGOING_DATA, onOutgoingData);
            _connection.addEventListener(PresenceEvent.PRESENCE, onPresence);
            _connection.addEventListener(RegistrationSuccessEvent.REGISTRATION_SUCCESS, onRegistrationSuccess);

            _connection.useAnonymousLogin = false;
            _connection.username = USERNAME;
            _connection.password = PASSWORD;
            _connection.server = SERVER;
            _connection.port = PORT;
            _connection.resource = RESOURCE_NAME;
            _connection.connect("flash");

            _keepAlive = new Timer(2 * 60 * 1000);
            _keepAlive.addEventListener(TimerEvent.TIMER, onKeepAliveLoop);

            _roster = new Roster(_connection);
            _roster.addEventListener(RosterEvent.ROSTER_LOADED, onRoster);
            _roster.addEventListener(RosterEvent.SUBSCRIPTION_DENIAL, onRoster);
            _roster.addEventListener(RosterEvent.SUBSCRIPTION_REQUEST, onRoster);
            _roster.addEventListener(RosterEvent.SUBSCRIPTION_REVOCATION, onRoster);
            _roster.addEventListener(RosterEvent.USER_ADDED, onRoster);
            _roster.addEventListener(RosterEvent.USER_AVAILABLE, onRoster);
            _roster.addEventListener(RosterEvent.USER_PRESENCE_UPDATED, onRoster);
            _roster.addEventListener(RosterEvent.USER_REMOVED, onRoster);
            _roster.addEventListener(RosterEvent.USER_SUBSCRIPTION_UPDATED, onRoster);
            _roster.addEventListener(RosterEvent.USER_UNAVAILABLE, onRoster);

            _people = new Dictionary();
        }

        private function buildRosterContent():void
        {
            // Add buttons for each user found in the roster.
            var i:uint = 0;
            for (var jid:String in _people)
            {
                _rosterCont.addChild(createButton(jid, i));
                i++;
            }
        }

        private function createButton(jid:String, counter:uint):Sprite
        {
            var sp:Sprite = new Sprite();
            sp.name = jid;
            sp.mouseChildren = false;
            sp.buttonMode = true;

            var tx:TextField = new TextField();
            tx.text = jid;
            tx.textColor = 0xF2F2F2;
            tx.autoSize = TextFieldAutoSize.LEFT;
            tx.y = 2;
            tx.x = 2;
            sp.addChild(tx);

            var gr:Graphics = sp.graphics;
            gr.beginFill(0x3A3A3A);
            gr.lineStyle(1, 0x1A1A1A);
            gr.drawRoundRect(0, 0, sp.width + 4, 22, 8, 8);
            gr.endFill();

            sp.addEventListener(MouseEvent.CLICK, onMouse);
            sp.addEventListener(MouseEvent.MOUSE_OVER, onMouse);
            sp.addEventListener(MouseEvent.MOUSE_OUT, onMouse);
            sp.x = 2;
            sp.y = (sp.height + 2) * counter + 2;
            return sp;
        }

        private function addMessage(from:EscapedJID, msg:String):void
        {
            var date:Date = new Date();
            _outputField.appendText("[" + date.getHours() + ":" + date.getMinutes() + " | " + from.node + "] " + msg + "\n");
        }

        private function onKeyUp(event:KeyboardEvent):void
        {
            switch(event.keyCode)
            {
                case Keyboard.ENTER :
                    messageSend();
                    break;
            }
        }

        private function onXiffError(event:XIFFErrorEvent):void
        {
            trace("onXiffError. " + event.toString());
            trace("onXiffError.errorMessage: " + event.errorMessage);
        }

        private function onIncomingData(event:IncomingDataEvent):void
        {
            trace("onIncomingData. " + event.toString());
        }

        private function onLogin(event:LoginEvent):void
        {
            trace("onLogin. " + event.toString());

            _keepAlive.start();

            var presence:Presence = new Presence(null, _connection.jid.escaped, null, null, null, 1);
            _connection.send(presence);
        }

        private function onMessage(event:MessageEvent):void
        {
            trace("onMessage. " + event.toString());
            addMessage(event.data.from, event.data.body);
        }

        private function onOutgoingData(event:OutgoingDataEvent):void
        {
            trace("onOutgoingData. " + event.toString());
        }

        private function onPresence(event:PresenceEvent):void
        {
            trace("onPresence. " + event.toString());
            var len:uint = event.data.length;
            for (var i:uint = 0; i < len; ++i)
            {
                var presence:Presence = event.data[i] as Presence;
                trace("onPresence. " + i + " show: " + presence.show);
                trace("onPresence. " + i + " type: " + presence.type);
                trace("onPresence. " + i + " status: " + presence.status);
                trace("onPresence. " + i + " from: " + presence.from);
                trace("onPresence. " + i + " to: " + presence.to);

                switch (presence.type)
                {
                    case Presence.SUBSCRIBE_TYPE :
                        // Automatically add all those to _roster whom have requested to be our friend.
                        _roster.grantSubscription(presence.from.unescaped, true);
                        break;
                    case Presence.SUBSCRIBED_TYPE :
                        break;
                }
            }
        }

        private function onRegistrationSuccess(event:RegistrationSuccessEvent):void
        {
            trace("onRegistrationSuccess. " + event.toString());
        }

        private function onRoster(event:RosterEvent):void
        {
            trace("onRoster. " + event.toString());
            switch (event.type)
            {
                case RosterEvent.ROSTER_LOADED :
                    buildRosterContent();
                    break;
                case RosterEvent.SUBSCRIPTION_DENIAL :
                    break;
                case RosterEvent.SUBSCRIPTION_REQUEST :
                    // If the JID is in the roster, accept immediately
                    if (_roster.getPresence(event.jid) != null)
                    {
                        _roster.grantSubscription(event.jid, true);
                    }
                    break;
                case RosterEvent.SUBSCRIPTION_REVOCATION :
                    break;
                case RosterEvent.USER_ADDED :
                    _people[event.jid.toString()] = event.data;
                    break;
                case RosterEvent.USER_AVAILABLE :
                    break;
                case RosterEvent.USER_PRESENCE_UPDATED :
                    break;
                case RosterEvent.USER_REMOVED :
                    break;
                case RosterEvent.USER_SUBSCRIPTION_UPDATED :
                    break;
                case RosterEvent.USER_UNAVAILABLE :
                    break;
            }
        }

        private function onMouse(event:MouseEvent):void
        {
            var sp:Sprite = event.target as Sprite;
            var tx:TextField = sp.getChildAt(0) as TextField;
            switch (event.type)
            {
                case MouseEvent.CLICK :
                    _chattingWith = new EscapedJID(sp.name);
                    _recipientField.text = _chattingWith.bareJID.toString();

                    var ros:RosterItemVO = _people[_chattingWith.toString()] as RosterItemVO;
                    trace(">> Roster data for " + _chattingWith.toString());
                    trace(">> displayName: " + ros.displayName);
                    trace(">> askType: " + ros.askType);
                    trace(">> priority: " + ros.priority);
                    trace(">> show: " + ros.show);
                    trace(">> pending: " + ros.pending);
                    trace(">> status: " + ros.status);
                    trace(">> subscribeType: " + ros.subscribeType);
                    trace(">> uid: " + ros.uid);

                    break;
                case MouseEvent.MOUSE_OVER :
                    tx.textColor = 0xFF40A1;
                    break;
                case MouseEvent.MOUSE_OUT :
                    tx.textColor = 0xF2F2F2;
                    break;
            }
        }

        private function onKeepAliveLoop(event:TimerEvent):void
        {
            _connection.sendKeepAlive();
        }
    }
}

Further visual and functional development is in your hands. Currently it will just list the people in your roster into the clickable boxes, which then set the value for the instant message recipient.