前兩天在cnblog上看到一個關於Flex的貼子,沒想到出於好怪心試用了一下確被它深深地吸引了。無論是UI美觀上或資料交換上都讓我感覺非常不錯,提供了remoting, HTTPService, WebService等組件靈活地和其他平台進行資料交換;基於動態類型的指令碼使用起來也很方便。Flex Builder2提供協助文檔也非常不錯,可惜全是英文看得比較辛苦(本人英文水平差)
大概花了一天的時間使用了一下,其實使用也很簡單。分別寫了一些使用HTTPService和WebService的例子。不過下面介紹的是如果建立一個美觀的DropDownList,先看一下:
Flex提供的控制項模型在建立這些群組控制項時非常簡單(可以說簡單到你不信)。看下整個mxml檔案的代碼:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application initialize="OnInit()" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.rpc.soap.WebService;
import mx.rpc.http.HTTPService;
public var initDG:Array = [
{Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99},
{Artist:'Pavement', Album:'Brighten the Corners', Price:11.99}
];
function OnInit():void
{
removeChild(myGrid);
SelectItem.popUp=myGrid;
}
function ItemChange():void
{
SelectItem.label= myGrid.selectedItem.Album;
}
]]>
</mx:Script>
<mx:DataGrid id="myGrid" dataProvider="{initDG}" x="10" y="40" change="ItemChange()" width="326" height="126">
<mx:columns>
<mx:DataGridColumn dataField="Artist"/>
<mx:DataGridColumn dataField="Album"/>
<mx:DataGridColumn dataField="Price"/>
</mx:columns>
</mx:DataGrid>
<mx:PopUpButton x="10" y="10" id="SelectItem"/>
</mx:Application>
實上可以通過HTTPService,WebService等組件和資料庫資料進行綁定,還可以加上靈活的資料過慮功能。
有時間寫一些關於如果調用WebService進行資料查詢,並綁定顯示結果。
如果對Flex有興趣的朋友可以瞭解一下,不會花太長時間就會有收穫。