Producer and Consumer : Producer Consumer « Development « Flex






Producer and Consumer

         
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="initApp()">
  <mx:TraceTarget/>  
  <mx:Script>
    
      import mx.controls.Alert;
      import mx.events.CollectionEvent;
      import mx.messaging.messages.AsyncMessage;
      import mx.messaging.events.MessageEvent;
      import mx.collections.ArrayCollection;
      [Bindable]
      private var myData:ArrayCollection = new ArrayCollection(
        [{name:"A", sales:5.00},
         {name:"B", sales:8.00},
         {name:"C", sales:2.00}]);
         
      private function initApp():void
      {
        myConsumer.subscribe();
        var message:AsyncMessage = new AsyncMessage();
        message.body = myData;
        myProducer.send(message);
      }
      private function messageHandler(event:MessageEvent):void
      {
        
        
      }
  
  </mx:Script>
  
  <mx:Producer id="myProducer" destination="dashboard"/>
  <mx:Consumer id="myConsumer" destination="dashboard" message="messageHandler(event)"/>
  
  
</mx:Application>

   
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Use Producer class to send message to Consumer