私は現在、Flex 4.5のネットワーキングの部分を学んでいます。私が検討しているコースでは、<s:HTTPService>
コンポーネントを使用してサーバに電話をかけたり、独自のカスタムサービスコールを使用して<s:CallResponder>
クラスを使用することをお勧めしますデータベース。本当にFlex 4の<s:CallResponder>クラスは何ですか?
コース自体とアドビのドキュメントの両方で、なぜ私がアプローチを取るべきかについて本当に良い説明が見つかりません。誰かがこれが良いアイデアである理由を説明してもらい、それが強く推奨されるケースを提供してもらえますか?
私が使っている簡単な例については、この例を参照してください。私は、<fx:Declarations>
タグセットの内部クラスのインスタンスを宣言し、そしてIはfetchData()
方法の内側にそれを使用する:応答者が成功に呼び出す関数への参照を含む変数を持つオブジェクトである
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
skinClass="skins.CustomAppSkin">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
private var booksCollection:ArrayCollection;
private function formatPrice(data:Object, columns:GridColumn):String {
return priceFormatter.format(data.price);
}
protected function fetchData(event:MouseEvent):void {
booksResponder.token = books.send();
}
protected function processXML(event:ResultEvent):void {
this.booksCollection = event.result.catalog.book;
}
protected function loadHandler(event:FaultEvent):void {
Alert.show(event.fault.faultString, event.fault.faultCode);
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="books" url="data/books.xml"/>
<s:CurrencyFormatter id="priceFormatter" currencySymbol="$" fractionalDigits="2" trailingZeros="true" useCurrencySymbol="true"/>
<s:CallResponder id="booksResponder" result="processXML(event)" fault="loadHandler(event)"/>
</fx:Declarations>
<s:Panel id="panel" title="Products" horizontalCenter="0">
<s:DataGrid dataProvider="{booksCollection}" height="400">
<s:columns>
<s:ArrayList>
<s:GridColumn headerText="Title" width="250" dataField="title"/>
<s:GridColumn headerText="Author" dataField="author"/>
<s:GridColumn headerText="Genre" width="100" dataField="genre"/>
<s:GridColumn headerText="Publish Date" width="100" dataField="publish_date"/>
<s:GridColumn headerText="Description" width="400" dataField="description"/>
<s:GridColumn headerText="Price (USD)" width="100" dataField="price" labelFunction="formatPrice"/>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<s:controlBarContent>
<s:Button id="getData" label="Get Data" click="fetchData(event)"/>
</s:controlBarContent>
</s:Panel>
</s:Application>
個人的には、ビューにサービスロジックを入れることを奨励していますが、それは本当に悪いアーキテクチャですが、次のバージョンのFlash Builderはより良い仕事をするでしょう。クリーンなアーキテクチャーは、オープンソースプロジェクトとしてFlexに関わっています。 –