Update: I’ve added some more features to FlashAIM, such as text formatting.
The community has been posting some pretty cool things made with Flex2. Andre Michelle’s blog has been filled with all sorts of interesting 3D and bitmap experiments. Darron Schall presented a preview of his VNC client which takes advantage of bitmap drawing and the new Socket api. Of course, I couldn’t let everyone upstage me, so with a couple weekends of work, I put together some classes for connecting to and interacting with AIM via the TOC 2.0 protocol. I made the basic user interface below just so I’d have a screenshot of the code in action.
At the moment, the TocConnection
class allows a user to log in, keep track of the status of buddies, send and receive messages, and set his or her own user info. I mainly wanted to get the most vital functions in place before releasing any code. I don’t know if I’ll expand it, but maybe I’ll start a project on OS-Flash so that the community can contribute.
Here’s an example of how to use TocConnection
in your own code. In the example, event handlers simple trace the output to the console. We start with initialization of the connection and adding listeners to the events. Generally, when a server message is received from AOL, an event is dispatched so listeners can update their status.
After initialization, and once you receive the connect event, you can start sending and receiving messages, and accessing other data. Here you’ll notice I set my user info right away, and sent a message to SOME_USER
. Normally you wouldn’t send automated messages like this, but you can start sending messages to other users after you receive the connection event. Finally, I loop through the list buddies for my account and trace them to the console.
package { import net.zeusdesign.im.aoltoc.*; import flash.display.Sprite; import flash.util.trace; public class ActionTalkTest extends Sprite { private var _aol:TocConnection; //the main connection class public function ActionTalkTest() { //the constructor takes host and port as params, but there are defaults this._aol = new TocConnection(); this._aol.addEventListener(TocEventType.CONNECT, onAolTocConnect); this._aol.addEventListener(TocEventType.DISCONNECT, onAolTocDisconnect); this._aol.addEventListener(TocEventType.ERROR, onAolTocError); this._aol.addEventListener(TocEventType.RECEIVE_MESSAGE, onAolTocReceiveMessage); this._aol.addEventListener(TocEventType.UPDATE_BUDDY, onAolTocUpdateBuddy); this._aol.connect("YOUR_SCREEN_NAME", "YOUR_PASSWORD"); //sorry, can't have mine } private function onAolTocConnect(event:TocEvent):Void { //set your user info this._aol.setUserInfo("This user is connected with ActionTalk."); //sendMessage takes a screen name and the message to send to it this._aol.sendMessage("SOME_USER", "Hi, I'm talking to you from Flash!"); //the following adds all your buddies to a string and traces it out var output:String = ""; for(var i:int = 0; iOther events include ERROR, RECEIVE_MESSAGE, and UPDATE_BUDDY. As far as I know, errors that you receive after sign-in aren't fatal. If you receive it beforehand, the server will drop the connection. When another user sends you a message, a specialized event tells you the screen name , his or her message, and if the message was automattcally sent (an away message). Another event is triggered whenever the state of one of your buddies changes. Typically, this happens one someone goes offline, becomes idle, or receives a warning.
//error event handler private function onAolTocError(event:TocErrorEvent):Void { trace("Toc Error: " + event.errorID + " " + event.message + " [" + event.raw + "]"); } //receive message event handler private function onAolTocReceiveMessage(event:TocImEvent):Void { var output:String = ""; //auto variable in TocImEvent marks auto-replies such as away messages if(event.auto) output += "Auto-Reply from "; //screenName refers to who sent the message and message is what they said output += event.screenName + ": " + event.message; trace(output); } //update buddy event handler private function onAolTocUpdateBuddy(event:TocUpdateBuddyEvent):Void { //generally updates online status, warning level, and idle time trace("Update Buddy: " + event.screenName + " " + event.online + " " + event.warningLevel); }That's it. The instant messenger source code is available. Get the free Flex 2 SDK from Adobe.
Nice dude! Well done, whats your next mission?
Great work!
It’s amazing what as3 is bringing!
Wait a second, what are you using that is using ActionScript 3.0? Even Flash Player 8 that just came out is AS 2.0.
Luke, an early version of AS3 has been released by Macromedia with FlexBuilder 2 and Flash Player 8.5. You can find it at labs.macromedia.com. I should warn you that it is an alpha pre-release, so don’t consider it ready for an actual website or anything. It’s just something to get us all salivating and hungry for more.
Nice, however it doesn’t work with the new Flex 2. Is there any way to open it?
Luke,
I updated the code to work with the official release of Flex 2 last night. I plan to make a post about it once I update a couple more projects.
About Flash’s Security:
If you can’t get it to run on your PC, you may have to set up a trusted folder through the Flash Player Global Security Settings panel. I usually add my Desktop to the list, and then I can run SWFs like this that require special network access from there.
I hope that helps.
Any idea how to fix a sandbox error? Is this a crossdomain.xml problem? I’ve set the Flash Player Global Security Settings via the link you posted above, so that’s not it.
Error #2044: Unhandled SecurityErrorEvent:.
text=Error #2048: Security sandbox violation: http://trip/hup/run/FlashAIM.swf
cannot load data from aimexpress.oscar.aol.com:5190.
at zeuslabs.im.aoltoc::TocConnection$iinit()
at FlashAIM/::_TocConnection1_i()
at FlashAIM$iinit()
at mx.managers::SystemManager/create()
at mx.managers::SystemManager/::initializeTopLevelWindow()
at mx.managers::SystemManager/::frameEndHandler()
Michael,
You have to run the SWF from somewhere on your own computer.
http://trip/hup/run/FlashAIM.swf
That URL indicates that you’re loading it from another computer and that puts Flash’s full security into effect.
All right then. The following run from OSX 10.4.7, Flash Player 9, Safari and Opera with Flash Player Security Settings to allow /Users/m/ and /Users/m/FlashAIM.swf
How about:
Error #2044: Unhandled SecurityErrorEvent:. text=Error #2048:
Security sandbox violation:
https://joshblog.net/FlashAIM.swf
cannot load data from aimexpress.oscar.aol.com:5190.
at zeuslabs.im.aoltoc::TocConnection$iinit()
at FlashAIM/::_TocConnection1_i()
at FlashAIM$iinit()
at mx.managers::SystemManager/create()
at mx.managers::SystemManager/::initializeTopLevelWindow()
at mx.managers::SystemManager/::frameEndHandler()
And
Error #2044: Unhandled SecurityErrorEvent:. text=Error #2048:
Security sandbox violation:
file:///Users/m/FlashAIM.swf
cannot load data from aimexpress.oscar.aol.com:5190.
at zeuslabs.im.aoltoc::TocConnection$iinit()
at FlashAIM/::_TocConnection1_i()
at FlashAIM$iinit()
at mx.managers::SystemManager/create()
at mx.managers::SystemManager/::initializeTopLevelWindow()
at mx.managers::SystemManager/::frameEndHandler()
Running the swf is no problem, but clicking ‘submit’ after typing in a sign on name and password results in a wait of a couple of minutes and the above security errors. Originally I thought this was a crossdomain problem but there’s no way to set policy at aol.com right, and I’m sure you got this working, so there must be something odd with my setup?
Josh, sorted. Thanks for the help.
Hi,
I am getting security error when I try to upload file to my server using FileReferenceList. I have tried your application and my own source code, both showing sandbox violation.
Error #2044: Unhandled SecurityErrorEvent:. text=Error #2049: Security sandbox violation: http://digitalmesh.com/AnzTest/Upload/Upload_wt1.swf cannot upload data to http://www.digitalmesh.com/AnzTest/upload/default.aspx.
Please check http://digitalmesh.com/AnzTest/Upload/FileUpload.html
or
http://digitalmesh.com/AnzTest/Upload/Upload_wt1.html
Please help,
Anz
Anz, Your two URLs have different subdomains. One says “digitalmesh.com” and the other “www.digitalmesh.com”. Though they probably point to the same place on your server, Flash insists that the subdomains match.
Open your example at http://www.digitalmesh.com/AnzTest/Upload/Upload_wt1.html (notice that I added www) and you won’t get the security error.
Hello. I’ve just downloaded your code and compiled it and have it running. I can log in and see my buddies list. However, when i try to send a message to the flash client, it does not seem to receive it, and when i send a message out from the flash client, it never reaches its target buddy. I’m just wondering if you have any suggestions for places that i could check, in the code, to see what i’m doing wrong (i’m running your example app), or if the protocol has changed…
Thanks!
Jos Yule, I recently fixed some bugs with sending messages. If you have a subversion client, the latest version of my AIM source code (now under the name MumbleLib), is available on Google Code.
Excellent. I’ve done a quick look over of the code – i like the new layout. I see that you’ve made it ready for other IM formats. Looks great – i’m excited to prototype some applications with this.
I’ve been working through your original example flex app, FlashAIM, trying to retro-fit the new MumbleLib code. While this is illuminating, it would be a huge help if you had any example code using the new lib available. If not, i will continue on with this conversion, and post it back to you when it is done (and working!).
Here is the proof-of-concept code that i’m using to test/work out how to use the new lib:
http://www.theorganization.net/work/jos/MumbleAIR.mxml
Now, it signs on, and i can see the signed on user. However, i am not receiving any messages sent in, or able to send any out. Do i need to have someone on my buddy list before i can send/receive messages? (i don’t think so).
Is there anything obvious that i’m missing/doing wrong?
Thanks again!
I’m currently working on an AIR client that uses MumbleLib. I intend to release an alpha version with source code as soon as I finish implementing a couple more features.
Jos, your code looks fine to me. It’s possible that AIMService may not know how to receive messages from contacts that aren’t on the user’s buddy list. I seem to remember running into that problem. I’ll put that on my list of things to fix.
Thanks for the update. I’ve added a check to see who is on the buddy list, and even when a user is on the buddy list i still can’t send out or receive messages.
Looking forward to your AIM AIR client!
Thanks Josh! This is a great help. Does anyone know of any Flex implementations for Yahoo, MSN Google?
Where can I obtain the latest AIM code?
Thanks,
-Steven
Steven, I remember that someone tried to connect to MSN in AS3 a while back, but he ran into some trouble with SSL and security stuff, so I think the project was filed away and never finished.
If you want the latest AIM code, check out my Mumble Messenger project.
Pingback: » Connecting to AIM with ActionScript 3 Sockets - ScatteredGenius.com
Hi,
Why do I get this error?
The only difference is in port number:
Error #2044: Unhandled SecurityErrorEvent:. text=Error #2048: Security sandbox violation: http://192.168.2.145/FlexCCSample.swf cannot load data from 192.168.2.145:10120
Hi guys I’m having some trouble with this error only using firefox.
I’m try to play a playlist on imeem.com and i always get this this error. I see it mention here but I don’t know what to do exactly in order to solve it since I’ve never done this before. Here’s the error :
Thank you in advance!
Can anyone just tell me what is AIM?
Im doing a project that needs to connect VC++ to AS3 using sockets.Is there any sockets available in AS3 with which i can connect my VC++ code to AS3??
Awaiting for a positive reply.
Thanking you
mnps
mnps, AIM == “AOL Instant Messenger”
You should be able to connect to a socket server created with C++ using the standard
flash.net.Socket
class in ActionScript 3.