Home >
In this post, we will focus on getting started with Adobe Flash Collaboration Services (formerly Cocomo). If you've heard of this, but aren't really sure what it is, AFCS is a hosted service provided by Adobe which enables real-time collaboration within your own Flex applications.
A better description from the AFCS site on Adobe Labs:
Adobe Flash Collaboration Service is a Platform as a Service that allows Flex developers to easily add real-time social capabilities into their RIA (rich Internet applications). Comprised of both Flex-based client components and a hosted services infrastructure, Adobe Flash Collaboration Service allows you to build real-time, multi-user applications with Flex in less time than ever before. And because Acrobat.com hosts the service, issues like deployment, maintenance, and scalability are taken care of for you.
This can be used for live chats, video chats, whiteboarding, and real-time collaboration, and is very easy to get started. Below, you'll find a quick example that I was able to put together this evening.
This example uses the default authentication provided by AFCS (requires and AFCS account), however you can override this to create your own authentication. In this example, you must use your Adobe AFCS username and password to log in:
In case you don't want to create an account and log in, here's what the UI looks like once you have logged in. It is really just a basic chat application:
This is a simlpe example, which I started by taking the "Simple Chat" example that comes with the AFCS SDK, and started playing around with it.
To get started, This first thing that you need to do is sign up for an account, and download the SDK at https://cocomo.acrobat.com/.
Once you have created an account and logged in, just click on the "Download SDK" button at the top of the screen. This will contain everything you need to get started... the swc libraries, documentation, and code examples.
I was able to put together this chat application in just minutes, after getting familiar with the API through the provided examples and documentation. The full source code is below. I changed very little from the original example... I just added a form that allows you to enter your user name and password, and used Panels to clean up the UI.
The two main AFCS components in this example are the AdobeHSAuthenticator, which is used to authenticate the AFCS accout, and the ConnectSessionContainer, which is used to contain the chat elements.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:rtc="AfcsNameSpace">
<mx:Script>
<![CDATA[
import com.adobe.rtc.pods.simpleChatClasses.ChatMessageDescriptor;
import com.adobe.rtc.events.ChatEvent;
import com.adobe.rtc.pods.simpleChatClasses.SimpleChatModel;
// This simple example just shows how this shared model can be made easily bindable for MXML.
// See SimpleChatModel for details.
[Bindable]
public var chatModel:SimpleChatModel;
protected function buildModel():void
{
// Create the model: just calling the constructor won't create the collection node or pass the messages.
// Call subscribe and give it a shared ID while creating the model.
// The shared ID becomes the name of the collection node.
chatModel = new SimpleChatModel();
chatModel.sharedID = "myChat_SimpleChatModel";
chatModel.subscribe();
chatModel.addEventListener(ChatEvent.HISTORY_CHANGE, onChatMsg);
this.addEventListener(KeyboardEvent.KEY_UP, onKeyStroke);
}
protected function submitChat(str:String):void
{
var cmd:ChatMessageDescriptor = new ChatMessageDescriptor();
cmd.displayName = cSession.userManager.getUserDescriptor(cSession.userManager.myUserID).displayName;
cmd.msg = str;
chatModel.sendMessage(cmd);
chat_mesg_input.text = "";
}
protected function clearChat():void
{
chat_mesg_area.text = "";
chatModel.clear();
}
protected function onChatMsg(p_evt:ChatEvent):void
{
if(p_evt.message != null && p_evt.message.msg != null && p_evt.message.displayName != null)
chat_mesg_area.text += "\r\n" + p_evt.message.displayName + ": " + p_evt.message.msg;
else
chat_mesg_area.text = "";
}
protected function onKeyStroke(p_evt:KeyboardEvent):void
{
if(p_evt.keyCode == Keyboard.ENTER) {
submitChat(chat_mesg_input.text);
}
}
private function doLogin() : void
{
auth.userName = username.text;
auth.password = password.text;
cSession.login();
loginForm.enabled = false;
}
private function onAuthSuccess( event : Event ) : void
{
vs.selectedIndex = 1;
buildModel();
}
private function onAuthfail( event : Event ) : void
{
loginForm.enabled = true;
}
]]>
</mx:Script>
<rtc:AdobeHSAuthenticator
authenticationSuccess="onAuthSuccess(event)"
authenticationFailure="onAuthfail(event)"
id="auth" />
<mx:ViewStack
id="vs"
top="10" left="10" right="10" bottom="10" >
<mx:Canvas width="100%" height="100%" >
<mx:Panel title="Login:"
horizontalCenter="0"
verticalCenter="0"
id="loginForm"
defaultButton="{ login }">
<mx:Form>
<mx:FormItem label="Username:" width="100%">
<mx:TextInput id="username" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Password:" width="100%">
<mx:TextInput id="password" width="100%" displayAsPassword="true"/>
</mx:FormItem>
</mx:Form>
<mx:ControlBar horizontalAlign="right">
<mx:Button id="login"
label="Login"
enabled="{ username.text.length > 0 && password.text.length }"
click="doLogin()"/>
</mx:ControlBar>
</mx:Panel>
</mx:Canvas>
<rtc:ConnectSessionContainer roomURL="put your room url here"
id="cSession"
authenticator="{auth}"
width="100%"
height="100%"
autoLogin="false">
<mx:Panel width="100%" height="100%" title="Simple Chat">
<mx:TextArea width="100%"
height="100%"
id="chat_mesg_area"/>
<mx:ControlBar>
<mx:TextInput width="100%" id="chat_mesg_input"/>
<mx:Button label="Submit Chat" click="submitChat(chat_mesg_input.text)"/>
<mx:Button label="Clear Chat" click="clearChat()"/>
</mx:ControlBar>
</mx:Panel>
</rtc:ConnectSessionContainer>
</mx:ViewStack>
</mx:Application>
___________________________________
Andrew Trice
Principal Architect
Cynergy Systems
http://www.cynergysystems.com




Facebook Application Development
One thing I know we need to do better is explain that your apps absolutely DO NOT require users to have an Adobe/AFCS account. You can set up your rooms to allow guests to come in with only their usernames, or hook up your own backend authentication systems to us, and let your users in that way, with the roles and permissions you want them to have. We definitely don't want to force your users to get identities w/ us. We're actually working on a new drop of the SDK with better docs / examples, to make this easier to do.
Thanks for the tutorial!
nigel
Don't forget you can also use the SimpleChatPod which will allow for one-to-one communications between chat users, and will also persist the chat content as well ... offers some nice management of chat content :-)
Hu? That's all? only those lines of code?
Nice!
Adobe is making things simpler that ever!
Great post Andrew. It's good to finally see some tutorials on AFCS getting out there.
Thanks Dan, AFCS is a big unknown to a lot of people out there. I'm thinking about doing a few more posts on it, as i dig deeper myself.
Can this be done in Flash CS4 or is this only available to Flex 3 users?
Can this be done in Flash CS4 or is this only available to Flex 3 users?
Can this be done in Flash CS4 or is this only available to Flex 3 users?
its not working in my system i have kept lib path to cocomo sdk also can you help me i am getting login box but after entering my id and password it is not going into next state,,...