I’m John C Bland II

Husband, Father, Tech Author, Deacon.
Founder of Katapult Media, and full-stack polyglot developer.
Political Free Agents Podcast Host.

I create. I launch.

YouTube Channel

I post regular fun on YouTube like me playing the bass and anything else I find fun. 

Get Something Built

All project work goes through Katapult Media. Business is open. Let’s chat.

I’m researching OpenAIM for an upcoming article and thought I’d share a few quick tidbits about connecting to OpenAIM. Let me first say…I didn’t do anything special here. AOL has provided a pretty quality developer center and they have written the ActionScript 3 code necessary for connecting to the AIM service. As a test I thought I’d try to grab my buddy list and show it in an mx:Tree component.

Disclaimer: This is purely a sample app so the code does not use any best practices or anything…just showing how to use the OpenAIM code.

Sample AIR app:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="https://www.adobe.com/2006/mxml" xmlns:wim="com.aol.api.wim.*"
                        layout="absolute"
                        applicationComplete="init()">
    <mx:Script>
        <![CDATA[
            import com.aol.api.wim.data.types.SessionState;
            import com.aol.api.wim.data.User;
            import com.aol.api.wim.data.Group;
            import com.aol.api.wim.Session;
            import com.aol.api.wim.data.BuddyList;
            import com.aol.api.wim.events.BuddyListEvent;
            import com.aol.api.wim.events.SessionEvent;
            private var aolSession:Session = new Session(stage, "your developer key", "Your Test Client", ".1");
            private var aolBuddyList:BuddyList;
            private function init():void{
                aolSession.addEventListener(SessionEvent.SESSION_STARTING, handleSessionStarting);
                aolSession.addEventListener(BuddyListEvent.LIST_RECEIVED, handleBuddyListLoad);
                aolSession.signOn("your username", "your password");
            }
            private function handleSessionStarting(event:SessionEvent):void{
                aolSession.requestBuddyList();
            }
            private function handleBuddyListLoad(event:BuddyListEvent):void{
                aolBuddyList = event.buddyList;
                updateBuddyList();
            }
            private function updateBuddyList():void{
                var buddyList:XML = <node label="AOL Buddy List" />
                var group:XML;
                var user:XML;
                for each(var item:Group in aolBuddyList.groups){
                    group = <node />
                    group.@label = item.label;
                    for each(var userItem:User in item.users){
                        if(userItem.state == SessionState.OFFLINE) continue;
                        user = <node />
                        user.@label = userItem.aimId;
                        group.appendChild(user);
                    }
                    buddyList.appendChild(group);
                }
                buddies.dataProvider = buddyList;
            }
        ]]>
    </mx:Script>
    <mx:Tree id="buddies" width="100%" height="100%" showRoot="false" labelField="@label" />
</mx:WindowedApplication>

So, briefly I’ll cover the code (gotta cook dinner in a sec; lol). On Line 4, above, we set the applicationComplete event to call our init() function, lines 19 to 23. In there we add a couple event listeners then call the signOn(..) function of the WIM api. Before we can successfully do this the aolSession variable must be created, which we do on line 15.

Note: You HAVE to get a developer key from AOL in order to test this code.

Once the sign on request is complete we call requestBuddyList(), line 26. When the buddy list is returned we set the aolBuddlyList variable then call updateBuddyList(), line 32. The updateBuddyList() function merely loops over the groups (your buddy groups) and users in each group, updates the buddyList XML local variable, then assigns it to the dataProvider of the buddies Tree component.

For the UI we mer
ely create an instance of mx:Tree and set the labelField to @label, which is what we created in the updateBuddyList() function.

That’s it. Run the app and you’ll see your buddy list in a window like below:

MyBuddyList

They have some work to do on the source code but I went from from 0 knowledge to this sample app in 20 or so minutes. Grab the code and check it out.