well, i'm not quite sure how they interact, but i think what happens is that flash is capable of keeping open sockets, which removes the need for the database. so, flash handles the data, and can either modify the page, or requires javascript to modify the page. the instant messaging thing should be relatively easier than the irc-like chat, i would think. there's plenty of free ones out there for you to kind of check out. also, channels on freenode are always a great resource - #flash, or #ajax
heck, you could even debug the AIM web based chat client.