Expand my Community achievements bar.

afcs -- chaining of events

Avatar

Level 3

Hi All,

After writing and delivering my first AFCS chat app, I'm looking for ways to better organize the code. I seem to do alot of chaining of events and similar.  Has anyone had any luck integrating AFCS with an mvcs framework?  Where would I begin.

Short of this can anyone recommend some design patterns which would help me chain events and references to samples using the same?

Thanks!

--Doug

2 Replies

Avatar

Level 3

I have it well integrated with pure MVC

I would recommend having a look at robot legs tho.

Here is the architecture for the Chat Module of Edoboard:


View: ChatView.xml

The layout of your chat.

Vbox, TextArea, Input, Send button etc..

Model Proxy: ChatProxy.as

Hold a reference to _chatModel:SimpleChatModel

override public function onRegister():void {

            // Afcs model
            _chatModel = new SimpleChatModel();
            _chatModel.sharedID = "edoboardChat";
            _chatModel.connectSession = ConnectSession.primarySession;
            _chatModel.subscribe();
            _chatModel.addEventListener(ChatEvent.HISTORY_CHANGE, onChatMsg);
}

We get the connection from the singleton ConnectSession, we could / should have a proxy to manage AFCS connection.

The proxy data is an array collection i use to hold messages, not usefull actualy but who knows.

onChatMsg i fire a notification

private function onChatMsg(e:ChatEvent):void {
            if (e.message != null )
                sendNotification(ApplicationFacade.CHAT_HISTORY, e.message);
}       

Mediator ChatMediator.as

It keeps a reference to _chatProxy and _userProxy which i used to get the current user First Name or the list of users connected.

Chat mediator listen for ApplicationFacade.CHAT_HISTORY notification.


override public function listNotificationInterests():Array {
            return [  ApplicationFacade.CHAT_HISTORY ];
        }

    override public function onRegister():void {
            _chatProxy = facade.retrieveProxy(ChatProxy.NAME) as ChatProxy;   
            _userProxy = facade.retrieveProxy(UsersProxy.NAME) as UsersProxy;   

               
            // Listeners
            chatView.chatButton.addEventListener(MouseEvent.CLICK, submitChat);     
        }

Lets sublmit message on click:

private function submitChat(e:MouseEvent):void {
            if(chatView.inputText.text != "") {
                var chatMessageDesc:ChatMessageDescriptor = new ChatMessageDescriptor();
                // Get my frstname
                chatMessageDesc.displayName = _userProxy.myUserName;
                chatMessageDesc.msg =  chatView.formatMessage(chatView.inputText.text);


                // publish
                _chatProxy.sendMessage(chatMessageDesc);


                chatView.clearInput();
                chatView.inputText.setFocus(); 
            }
}

Notification Handling

        override public function handleNotification( note:INotification ):void {
            switch ( note.getName() ) {
                case ApplicationFacade.CHAT_HISTORY:
                        /* [..] simplified for example */
                        var msgDescriptor:ChatMessageDescriptor = note.getBody() as ChatMessageDescriptor;
                         chatView.addMessage(msgDescriptor.msg);

                    break;
            }
        }

Hope that gives you an idea of how to integrate afcs in a flex/as3 framework.

Avatar

Former Community Member

Awesome stuff - it's American thanksgiving holiday here, so things might be

a little slow for "official" responses - it's great to see folks helping

each other out!

thanks

nigel