Use AsyncMessage class to send out message : AsyncMessage « Data Model « Flex






Use AsyncMessage class to send out message

           
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
  creationComplete="myConsumer.subscribe();">

  <mx:Script>
    
      import mx.controls.Alert;
      import mx.messaging.events.MessageEvent;
      import mx.messaging.messages.AsyncMessage;
      private function sendMessage():void  
      {
        var message:AsyncMessage = new AsyncMessage();
        message.body = "message";
        message.headers.chatUser = "Tom";
        myProducer.send(message);
      }
      private function messageHandler(event:MessageEvent):void
      {
        msgLog.text += event.message.headers.chatUser + ": " + event.message.body + "\n";
      }
  
  </mx:Script>

  <mx:Producer id="myProducer" destination="chat"/>
  <mx:Consumer id="myConsumer" destination="chat" message="messageHandler(event)" selector=""/>
    

  <mx:Button label="Send Message" click="sendMessage()"/>
  <mx:TextArea id="msgLog" editable="false" height="200" width="100%"/>
  
</mx:Application>

   
    
    
    
    
    
    
    
    
    
    
  








Related examples in the same category