Connecting to an XMPP / Jabber Server with the XIFF AS3 Library
As I mentioned earlier, I am starting to build an XMPP chat client for the XMPP / Jabber community server I set up today. I am using the XIFF ActionScript 3 library. While the library seems to be pretty solid, there is not a ton of documentation for it right now.
Here is a simple example that shows how to connect to an XMPP / Jabber server, join a room, and send a message to the room. The example assumes that you already have a username and password on the server (I havent figured out how to get it to connect anonymously yet):
// ActionScript file
import org.jivesoftware.xiff.conference.Room;
import org.jivesoftware.xiff.core.JID;
import org.jivesoftware.xiff.core.XMPPSocketConnection;
import org.jivesoftware.xiff.events.LoginEvent;
import org.jivesoftware.xiff.events.RoomEvent;
import org.jivesoftware.xiff.events.XIFFErrorEvent;
private var connection:XMPPSocketConnection;
private function onCreationComplete():void
{
connection = new XMPPSocketConnection();
connection.username = "test";
connection.password = "test";
connection.server = "mesh.local";
connection.port = 5222;
connection.addEventListener(LoginEvent.LOGIN, onLogin);
connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, onError);
connection.connect("standard");
}
private function onLogin(e:LoginEvent):void
{
var room:Room = new Room(connection);
room.roomJID = new JID("test@conference.mesh.local");
room.addEventListener(RoomEvent.ROOM_JOIN, onRoomJoin);
room.join();
}
private function onRoomJoin(e:RoomEvent):void
{
Room(e.target).sendMessage("im here");
}
private function onError(e:XIFFErrorEvent):void
{
trace(e.errorCode);
}
Thanks go out to Mitchell Hashimoto who helped me figure this out over on the XIFF forums.






Funny … my to-do list still has “finish XIFF documentation.” Perhaps one day in the distant future I will get to that :) In the meantime, the code has asdoc comments so you can at least use that to generate the basics.
Sean
14 Aug 08 at 5:02 pm
That’s a handy example, much shorter than the ‘minimal’ one I’ve been using for testing.
Instead of connection.username and connection.password, you can set connection.useAnonymousLogin to true to, uh, use anonymous log-in. To me a while to figure that that was all there was to it!
Tom Carden
14 Aug 08 at 5:55 pm
Thanks Mike! This is exactly what I was looking for!
Tim Denney
14 Aug 08 at 7:30 pm
I have developed an Desktop instant messenger Velvetpuffin using XIFF library with mProjector two years before. Instant messenger have features to chat with yahoo,msn,gtalk,icq buddies with sharing of photos and blog. That time it is in actionscript 2.0. But the product failure due to performance (mProjector) issue and limitation in passing objects to multiple windows in desktop. You can view the video demo at http://velvetpuffin.vox.com/. After that I have not tuched XIFF library. After seeing your sample, I am thinking of developing desktop client using AIR. Hope performance issue may not come in AIR.
-Santhakumar
http://www.my3dwall.com
santhakumar
14 Aug 08 at 8:12 pm
The lack of documentation, in my opinio,n is hampering the wide-spread adoption of XIFF. I believe it should be of importance that some “quick start guide” or “tutorial series” should be set up for developers interested in XIFF.
William from Lagos
15 Aug 08 at 2:03 am
[...] Looking at even the simplest of code like this (taken from Mike Chamber’s XMPP server in ActionScript 3) [...]
Optional typing and dynamic languages on Dion Almaer's Blog
15 Aug 08 at 8:52 am
I agree, so far I’m absolutely loving XIFF except for
1. The name, I don’t think the AS API should be named the same as the messaging format it uses.
2. No examples or quick start guides.
I just switched over to XIFF from using WIMAS3, which was just awful. I don’t know how that got any popularity and it seems that XIFF is still an unknown. It will catch on though, it just needs a little marketing!
Nick Bilyk
15 Aug 08 at 9:17 am
[...] Connecting to an XMPP / Jabber Server with the XIFF AS3 Library ???????http://blog.minidx.com/2008/08/16/1260.html [...]
??XIFF AS3 Library????XMPP / Jabber?????? - ??Flex??
15 Aug 08 at 7:04 pm
You should also check out the Spark project also Flex, also from Jive, also very cool. And it probably already does a tonne of the stuff you were thinking of trying.
Jesse
17 Aug 08 at 8:57 pm
have anyone created groups using xiff
vinod
18 Aug 08 at 12:51 am
@Tom Carden
Thanks. That worked for logging in anonymously. Do you know how to set the user name though? I just get an ID in the chat room now.
mike chambers
mesh@adobe.com
mikechambers
18 Aug 08 at 10:13 am
[...] I posted some code the other day that showed how to use the XIFF AS3 Library to connect to an XMPP server and join a group chat room. [...]
Mike Chambers » Blog Archive » Connecting Anonymously to an XMPP Group Chat using XIFF
18 Aug 08 at 10:54 am
Awesome! I just started looking into chat for Flash. I had no idea one could connect with/like Jabber. That makes my day.
Chris
17 Oct 08 at 5:48 pm
Hi guys, this seems pretty much simple to me, but when i try to implement this, doesnt work! It simply dont join the room nor activate any callback (onxiferror, roomjoin, roomkick, etc). Anyone can give me a clue? Openfire logs dont tell me nothing! I can connect an send messages to normal user, but nothing happens when try to join or create the room. I copied your example as is, but nothing happens again. Any help will be much appreciate!
Marco
21 Nov 08 at 6:32 am