Accessibility

Table of Contents

Invoking .NET objects using the Flex RemoteObject API

Putting everything together

A complete listing of the client-side code is available below. You can also download the complete file from the sample files archive in the Requirements section of the article:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
  layout="absolute" width="365" height="268">
  <mx:Script>
  <![CDATA[
     import flash.net.registerClassAlias;
     import mx.controls.Alert;
     import mx.rpc.events.FaultEvent;
     import com.examples.TickerInfo;
     import mx.rpc.events.ResultEvent;
          
     [Bindable]
     private var quote:TickerInfo;
          
      public function handleClick():void
      {
         tickerInfoService.getTickerInfo( symbolText.text );
      }
           
      public function gotServerData( event:ResultEvent ):void
      {
         quote = event.result as TickerInfo;
      }
           
      public function faultHandler( event:FaultEvent ):void
      {
        Alert.show( "Server reported an error " + event.fault.faultString, "Server Error" );
      }
  ]]>
  </mx:Script>
  <mx:RemoteObject id="tickerInfoService"
     destination="GenericDestination"
     source="GettingStarted.Examples.StockQuoteService"
     showBusyCursor="true"
     fault="faultHandler(event)" >
     <mx:method name="getTickerInfo" result="gotServerData(event)"/>
  </mx:RemoteObject>   
   
  <mx:Panel x="10" y="10" width="345" height="248" 
     layout="absolute" title="Sample Flex to .NET application">
     <mx:TextInput id="symbolText" x="120.5" y="19" width="100"/>
     <mx:Label x="29.5" y="21" text="Ticker Symbol:"/>
     <mx:Button x="228.5" y="19" label="Get data" width="67" click="handleClick()"/>
     <mx:Canvas x="29.5" y="71" width="266" height="116" 
       borderColor="#4f809d" borderStyle="solid" cornerRadius="10" 
       backgroundColor="#64a6c6" backgroundAlpha="0.43"  
       horizontalScrollPolicy="off" verticalScrollPolicy="off">
         <mx:Label x="10" y="36" text="Bid:"/>
         <mx:Label x="10" y="62" text="Ask:"/>
         <mx:Label x="10" y="10" text="Price:"/>
         <mx:Label x="10" y="88" text="Timestamp"/>
         <mx:Label x="87" y="10" fontWeight="bold" text="{quote.lastPrice}"/>
         <mx:Label x="87" y="36" fontWeight="bold" text="{quote.currentBid}"/>
         <mx:Label x="87" y="62" fontWeight="bold" text="{quote.currentAsk}"/>
         <mx:Label x="87" y="88" fontWeight="bold" text="{quote.lastPriceTimeStamp}"/>
     </mx:Canvas>
      <mx:Label x="29.5" y="51" text="Server response:"/>
   </mx:Panel>   
</mx:Application>

Where to go from here

Flex and .NET integration through WebORB enables many possibilities. Flex Remoting is not limited to just primitive data types. Method arguments and return types can be .NET collections, arrays, custom data types (as seen in this example), ADO.NET classes, enumerations and many more. Integration makes it possible to leverage existing ASP.NET applications while creating new and exciting Flex-based user interfaces.

You can explore Flex/.NET integration examples featured in WebORB management console. The console is available at http://localhost/weborb30 in a default installation.