終於把628頁的《Flex3/ RIA完全手冊》看完了,而且在我的計劃之內,所以這裏也給自己鼓勵一下哦,(聲明:不是爲了顯擺,也不是爲了誇自己多麼多麼能看厚書)因爲這確實是我第一次看完這麼厚的技術書籍。比如,我的《JSP寶典》已經買下半年多了,但我到現在還沒看完,所以現在我索性把她放在那裏當字典或資料查了,同學看見這本書都叫它“葵花寶典”,呵呵(足可見它的厚度吧),希望下面這兩個月能夠再接再勵,爭取突破這個高度,有的時候發現計算機的書籍真的一個比一個厚,我相信每一個大牛或大師級別的人大多也是這麼過來的吧,呵呵既然拜讀了這本《Flex3/ RIA完全手冊》,也談一下自己的心得體會,讀書重在應用和交流嘛:
先聲明下我不是誰的託,也不是在這裏宣傳這本書有多麼多麼的好,因爲我也是從學校的圖書館裏借來拜讀的,接下來的時間本該馬上開始另外一本書籍的學習,但是我下個學習任務中需要的開發工具和平臺還沒Down下來,所以就在這裏碼開文字消遣一會兒了!哈哈
大概說下這本書的內容組織結構:
第一篇 基礎篇
說了下flex特性,Flex Builder3的安裝與開發環境講解,MXML的介紹,flex3.0程序的編譯、調試、運行等
第二篇 ActionScript3.0基礎
也是些基礎性的東西,比如:AS語法與基礎、AS中的數據類型、運算符和表達式、程序設計的基本結構、函數,面向對象基礎,數字處理,日期與時間,字符串,數組,XML等,對於JAVA Programmer來說這些可以一帶而過哦,因爲確實很簡單嘛
第三篇 組件篇
用組件構建Flex界面、界面設計等,有不少界面製作的實例,到時候一併把源代碼發上來,還有自定義效果美化界面,CSS美化界面(包含濾鏡的使用)flex美化應用(自定義界面屬性和外觀等),總之這張的實例還是蠻多的
第四篇 數據篇
Flex中的數據處理(數據綁定、數據存儲、數據驗證、格式化等)、使用正則表達式匹配字符串數據、數據的傳輸方式(文件流、XML等方式)、數據的交互(HTTPService與HTTP的交互、WebService交互,Fluorine網關與.net類的交互(java的可以不看這個哦))。
第五篇 擴展篇
着重講了一個開發框架Cairngorm,包括Cairngorm源代碼中類的介紹、框架的運行原理,還有一個實例,另外還介紹了flex3的新特性(相比Flex2),比如加載PDF文件,使用本地的SQL數據庫,Flex3.0中的Ajax技術,Flex-Ajax Bridge控制技術等
第六篇 實例篇
實例篇主要介紹了三個經典案例:FLV播放器,對Adobe官方經典實例CairngormStore的分析與講解算是詳盡,擴展應用就得看個人造化了,最後一個實例比較有趣,客戶端用Flex3實現,服務器端用java實現,通過LiveCycle Data Services服務器(被稱作AMF網關)調用服務器端的程序來操作SQL2000數據庫及其本地文件。
總體感覺這本書還行,容易上手,適合Flex3初學者,實例比較豐富,講解也很透徹,如果對RIA富互聯網應用程序感興趣的朋友不妨可以一讀,在此也公佈自己這段學習期間的所有源代碼,以供各位programmer交流,也希望你們如果有什麼好的Flex/RIA方面的參考書籍也一併推薦哦!
偶的交流暫且就碼到這裏了,期待你們給我提供更好的RIA參考資料或書籍哦!哈哈
我交流我快樂,相信你們也是一樣的!Sharing你們手中的每一本資料,那麼你將會得到更大的收穫!
下面貼一點界面設計實戰和FLV播放器的源代碼:(FLV用到了Cairngorm框架,自己去Adobe上下載一下吧)還有剩下的實例源代碼我會陸續整理好打包傳上來!
PS:恕不接受個人郵件發送,不要說“發個源代碼到我郵箱吧”,也不要像在百度知道上那樣發個“跪求XXXXXXXX源程序之類”的帖子。。。,我想作爲開發者看到這樣的字樣除了嘔吐和鄙視,那麼接下來就是好幾天吃不下飯了!相信JE上肯定沒有這樣的人!
Flex3界面設計綜合實例源代碼(最好下載我傳上來的附件):
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()"> <mx:states> <mx:State name="index"> <!--新建"index"狀態--> <mx:RemoveChild target="{panel1}"/> <!--移除登陸框--> <mx:SetStyle name="fontFamily" value="Georgia"/> <mx:SetStyle name="fontSize" value="12"/> <mx:SetStyle name="fontWeight" value="bold"/> <mx:AddChild position="lastChild"> <mx:Panel width="400" height="300" layout="absolute" horizontalCenter="0" verticalCenter="0" borderColor="#04D8F8" title="菜單導航" fontSize="14" fontFamily="Arial" id="panel2"> <mx:MenuBar id="myMenuBar" dataProvider="{myXMLList}" labelField="@id" showRoot="false" width="380" fontSize="12" fontFamily="Georgia" fontWeight="normal" change="menuClickHandle(event)"/> </mx:Panel> </mx:AddChild> </mx:State> <mx:State name="index1" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox height="240" id="myVBox1" x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" width="{myMenuBar.width}" backgroundColor="#FA0505" backgroundAlpha="0.5"> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="index2" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" height="240" id="myVBox2" backgroundAlpha="0.5" backgroundColor="#F5E531" width="{myMenuBar.width}"> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="index3" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" height="240" width="{myMenuBar.width}" backgroundAlpha="0.5" backgroundColor="#8DF531" id="myVBox3"> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="index4" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" height="240" id="myVBox4" backgroundColor="#31F5E5" backgroundAlpha="0.5" width="{myMenuBar.width}"> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="index5" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" height="240" id="myVBox5" backgroundColor="#D731F5" backgroundAlpha="0.5" width="{myMenuBar.width}"> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="columnIndex" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <!--柱狀圖--> <mx:ColumnChart id="myColumnChart" dataProvider="{finance}" horizontalCenter="0" verticalCenter="12" width="360" height="220"> <mx:horizontalAxis><!--定義橫座標綁定到"finance"數據集中的"Month"上--> <mx:CategoryAxis dataProvider="{finance}" categoryField="Month" title="(月份)"/> </mx:horizontalAxis> <mx:series> <mx:ColumnSeries displayName="收入" xField="Month" yField="In"/> <mx:ColumnSeries displayName="支出" xField="Month" yField="Out"/> </mx:series> </mx:ColumnChart> </mx:AddChild> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <!--Legend組件綁定柱狀圖中的數據名--> <mx:Legend dataProvider="{myColumnChart}" x="291" y="30"/> </mx:AddChild> </mx:State> <mx:State name="piechartIndex" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <!--餅狀圖--> <mx:PieChart id="myPieChart" dataProvider="{itProgrammer}" showDataTips="true" horizontalCenter="0" verticalCenter="8" width="360" height="220"> <mx:series> <mx:PieSeries labelPosition="callout" labelFunction="displayCount" field="count"> <mx:calloutStroke> <mx:Stroke weight="0" color="0x888888" alpha="1.0"/> </mx:calloutStroke> <mx:radialStroke> <mx:Stroke weight="0" color="#ffffff" alpha="0.5"/> </mx:radialStroke> <mx:stroke> <mx:Stroke weight="2" color="0" alpha="0.5"/> </mx:stroke> </mx:PieSeries> </mx:series> </mx:PieChart> </mx:AddChild> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:Legend dataProvider="{myPieChart}" x="10" y="26"/> </mx:AddChild> </mx:State> <mx:State name="fileIndex" basedOn="index"> <mx:RemoveChild target="{panel2}"/> <mx:AddChild position="lastChild"> <mx:Panel width="800" height="600" layout="absolute" horizontalCenter="0" verticalCenter="0" id="filePanel" title="文件目錄瀏覽器實例" borderColor="#04A5F9"> <mx:VBox height="100%" width="100%" horizontalCenter="0" verticalCenter="0"> <mx:HBox width="100%" y="0"> <mx:FileSystemComboBox id="filecmb" directory="{filedg.directory}" directoryChange="filedg.directory=filecmb.directory;"/> <mx:Button label="返回" id="btnBack" click="filedg.directory=filedg.directory.parent"/> </mx:HBox> <mx:FileSystemDataGrid width="100%" height="400" y="0" x="0" id="filedg" dataProvider="{new File('e:/')}"/> </mx:VBox> </mx:Panel> </mx:AddChild> </mx:State> <mx:State name="IEindex" basedOn="index"> <mx:RemoveChild target="{panel2}"/> <mx:AddChild position="lastChild"> <mx:Panel width="800" height="600" layout="absolute" horizontalCenter="0" verticalCenter="0" borderColor="#05B8FB" id="htmlPanel" title="FlEX瀏覽器"> <mx:VBox x="0" y="0" height="100%" width="100%"> <mx:HBox width="100%" height="30" backgroundColor="#DDFADD" verticalAlign="middle"> <!--"mx:Spacer"標籤是空格組件,可定義寬度和高度--> <mx:Spacer width="100%"/> <!--網址輸入框--> <mx:TextInput id="txtURL" width="450" x="{(htmlPanel.width-txtURL.width)/2}"/> <!--實現網頁跳轉--> <mx:Button id="btnGOTO" label="GO!" click="gotoURL()"/> <mx:Spacer width="100%"/> </mx:HBox> <!--"mx:HTML"組件使得AIR程序可集成網頁--> <mx:HTML id="html" width="800" height="600" location="http://www.google.cn"/> </mx:VBox> </mx:Panel> </mx:AddChild> </mx:State> <mx:State name="txtEditorIndex" basedOn="index"> <mx:RemoveChild target="{panel2}"/> <mx:AddChild position="lastChild"> <mx:Panel width="482" height="350" layout="absolute" horizontalCenter="0" verticalCenter="0" borderColor="#03DCFC" id="txtPanel" title="簡單的文本編輯器"> <mx:Label x="28" y="10" text="文件路徑" id="pathLabel"/> <mx:TextInput x="102" y="8" width="277" id="txtFilePath"/> <mx:Button x="387" y="8" label="瀏覽..." id="btnChooseFilePath" click="dlgFile.browseForOpen('瀏覽文件',[txtFilter,jpgFilter,gifFilter,bmpFilter,pngFilter,docFilter,fileAll]);dlgFile.addEventListener(Event.SELECT,selectHandle);"/> <mx:TextArea x="28" y="50" width="424" height="211" id="txtContent"/> <mx:Button x="28" y="275" label="修改" id="txtModify" click="modifyText()"/> </mx:Panel> </mx:AddChild> </mx:State> <mx:State name="AStoJSIndex" basedOn="index"> <mx:RemoveChild target="{panel2}"/> <mx:AddChild position="lastChild"> <mx:Panel width="400" height="300" layout="absolute" horizontalCenter="0" verticalCenter="0" borderColor="#06D6FB" id="astojsPanel" title="AS調用JS實例"> <mx:TextInput x="10" y="44" id="txtName" text="[請輸入名字]"/> <mx:Button x="191" y="44" label="確定" id="btnConnect" click="invokeJavaScript()"/> <mx:Label x="10" y="114" id="lblResult"/> </mx:Panel> </mx:AddChild> </mx:State> <mx:State name="dragIndex" basedOn="index"> <mx:RemoveChild target="{panel2}"/> <mx:AddChild position="lastChild"> <mx:Panel width="400" height="300" layout="absolute" id="dragPanel" title="組件拖拽實例" borderColor="#06C9FA" horizontalCenter="0" verticalCenter="0" creationComplete="initListApp()"> <mx:HBox width="100%" horizontalCenter="0" verticalCenter="0" height="100%"> <mx:VBox height="100%" width="50%"> <mx:Label id="lblLeft" text="左列表"/> <!--定義左列表,允許拖拽--> <mx:List width="100%" height="100%" id="list1" allowMultipleSelection="true" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true"> </mx:List> </mx:VBox> <mx:VBox height="100%" width="50%"> <mx:Label text="右列表" id="lblRight"/> <!--定義右列表,允許拖拽--> <mx:List width="100%" height="100%" id="list2" allowMultipleSelection="true" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true"> </mx:List> </mx:VBox> </mx:HBox> </mx:Panel> </mx:AddChild> </mx:State> <mx:State name="blurIndex" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" height="240" id="myVBox6" backgroundAlpha="0.8" width="{myMenuBar.width}"> <mx:Image source="images/Vista.jpg" width="400" height="300" horizontalCenter="0" verticalCenter="20"/> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="dissolveIndex" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" id="myVBox7" width="{myMenuBar.width}"> <mx:Image source="images/scene.jpg" width="400" height="290"/> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="fadeIndex" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" id="myVBox8" width="{myMenuBar.width}"> <mx:Image x="10" y="30" source="images/scene02.jpg" width="400" height="300"/> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="resizeIndex" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" id="myVBox9" width="{myMenuBar.width}"> <mx:Image x="0" y="21" source="images/dog.jpg" width="400" height="300"/> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="rotateIndex" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" id="myVBox10" width="{myMenuBar.width}"> <mx:Image source="images/gulinshanshui.jpg" horizontalCenter="0" verticalCenter="0" width="400" height="300"/> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="soundIndex" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" id="myVBox11" width="{myMenuBar.width}"> <mx:Image source="images/scene02.jpg" horizontalCenter="0" verticalCenter="0" width="400" height="300" autoLoad="true" mouseDownEffect="{mySoundEffect}"/> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="zoomIndex" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:VBox x="{myMenuBar.x}" y="{myMenuBar.y+myMenuBar.height}" id="myVBox12" width="{myMenuBar.width}"> <mx:Image width="400" height="300" horizontalCenter="0" verticalCenter="0" source="images/eruanshi.jpg"/> </mx:VBox> </mx:AddChild> </mx:State> <mx:State name="swfIndex" basedOn="index"> <mx:RemoveChild target="{panel2}"/> <mx:AddChild position="lastChild"> <mx:Panel width="800" height="200" layout="absolute" horizontalCenter="0" verticalCenter="0" borderColor="#00B9FD" backgroundImage="{bgSWF}"> </mx:Panel> </mx:AddChild> </mx:State> <mx:State name="filterIndex" basedOn="index"> <mx:AddChild relativeTo="{panel2}" position="lastChild"> <mx:Label text="Hello Flex3/RIA—我的界面我做主!" fontSize="20" filters="{[new DropShadowFilter(10,35)]}" horizontalCenter="0" verticalCenter="0" color="#FB04DB"/> </mx:AddChild> </mx:State> </mx:states> <mx:transitions> <mx:Transition id="myTransition1" fromState="*" toState="index1"> <mx:Parallel target="{myVBox1}"> <mx:WipeDown duration="2000"/> <mx:Dissolve alphaFrom="0.0" alphaTo="1.0" duration="2000"/> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition2" fromState="*" toState="index2"> <mx:Parallel target="{myVBox2}"> <mx:WipeUp duration="2000"/> <mx:Dissolve alphaFrom="0.0" alphaTo="1.0" duration="2000"/> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition3" fromState="*" toState="index3"> <mx:Parallel target="{myVBox3}"> <mx:WipeLeft duration="2000"/> <mx:Dissolve alphaFrom="0.0" alphaTo="1.0" duration="2000"/> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition4" fromState="*" toState="index4"> <mx:Parallel target="{myVBox4}"> <mx:WipeRight duration="2000"/> <mx:Dissolve alphaFrom="0.0" alphaTo="1.0" duration="2000"/> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition5" fromState="*" toState="index5"> <!--效果組合,對象爲myVBox5--> <mx:Parallel target="{myVBox5}"> <!--模糊的擴散效果 --> <mx:Blur blurXFrom="0" blurXTo="180" blurYFrom="0" blurYTo="150" duration="2000"/> <!--透明度漸變效果--> <mx:Dissolve alphaFrom="0.0" alphaTo="1.0" duration="2000"/> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition6" fromState="*" toState="blurIndex"> <!--效果組合,對象爲myVBox6--> <mx:Parallel target="{myVBox6}"> <mx:Blur id="myBlur" blurXFrom="0" blurXTo="20" blurYFrom="0" blurYTo="20"/> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition7" fromState="*" toState="dissolveIndex"> <!--效果組合,對象爲myVBox7--> <mx:Parallel target="{myVBox7}"> <mx:Dissolve id="myDissolve" alphaFrom="1.0" alphaTo="0.5" color="white" duration="4000" targetArea="{new RoundedRectangle(20,20,320,180)}"/> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition8" fromState="*" toState="fadeIndex"> <!--效果組合,對象爲myVBox8--> <mx:Parallel target="{myVBox8}"> <mx:Fade id="myFade" alphaFrom="0.0" alphaTo="1.0" duration="4000"/> <!--<mx:Glow id="myGlow" alphaFrom="0.2" alphaTo="0.8" blurXFrom="100" blurXTo="0" blurYFrom="100" blurYTo="0" color="yellow" inner="true" knockout="true" strength="5"/>--> <!--<mx:Move id="myMove" xBy="2" xFrom="10" xTo="50" yBy="5" yFrom="10" yTo="50"/>--> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition9" fromState="*" toState="resizeIndex"> <!--效果組合,對象爲myVBox9--> <mx:Parallel target="{myVBox9}"> <mx:Resize id="myResize" heightBy="2" heightFrom="300" heightTo="430" widthBy="4" widthFrom="400" widthTo="540" duration="1000"/> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition10" fromState="*" toState="rotateIndex"> <!--效果組合,對象爲myVBox10--> <mx:Parallel target="{myVBox10}"> <mx:Rotate id="myRotate" angleFrom="0" angleTo="180" originX="200" originY="150"/> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition11" fromState="*" toState="soundIndex"> <!--效果組合,對象爲myVBox11--> <mx:Parallel target="{myVBox11}"> <mx:SoundEffect id="mySoundEffect" autoLoad="true" bufferTime="200000" loops="3" startTime="0" useDuration="true" volumeFrom="0.5" volumeTo="2.0" source="sound\changhai.mp3"/> </mx:Parallel> </mx:Transition> <mx:Transition id="myTransition12" fromState="*" toState="zoomIndex"> <!--效果組合,對象爲myVBox12--> <mx:Parallel target="{myVBox12}"> <mx:Zoom id="myZoom" zoomHeightFrom="1.0" zoomWidthFrom="1.0" zoomHeightTo="2.0" zoomWidthTo="2.0"/> </mx:Parallel> </mx:Transition> </mx:transitions> <mx:Panel width="400" height="300" layout="absolute" id="panel1" title="用戶登陸" fontSize="14" horizontalCenter="0" verticalCenter="2" borderColor="#06B6F7"> <mx:Button label="登陸" horizontalCenter="-87" verticalCenter="76" id="btnLogin" click="loginHandle()"/> <mx:Button label="重置" horizontalCenter="80" verticalCenter="76" id="btnReset" click="resetHandle()"/> <mx:Label text="用戶名:" horizontalCenter="-91" verticalCenter="-52" id="label1"/> <mx:Label text="密 碼:" horizontalCenter="-90" verticalCenter="-19" id="label2"/> <mx:TextInput horizontalCenter="28" verticalCenter="-52" id="txtUsername"/> <mx:TextInput horizontalCenter="28" verticalCenter="-19" id="txtPassword" displayAsPassword="true"/> <mx:Label x="69" y="132" text="檢驗碼:" id="labelCheck"/> <mx:TextInput x="138" y="130" id="txtCheck" width="69"/> <mx:Label id="codeLabel" horizontalCenter="53" verticalCenter="16" fontSize="16" fontWeight="bold" color="#F71106"/> <mx:LinkButton x="275" y="134" label="看不清楚?" id="againCode" click="initApp()" fontSize="10"/> </mx:Panel> <mx:Script> <![CDATA[ import flash.filters.DropShadowFilter; import mx.graphics.RoundedRectangle; import flash.external.ExternalInterface; import flash.filesystem.*;//引用filrsystem包 import flash.net.FileFilter;//應用FileFilter類 import mx.collections.ArrayCollection; import mx.controls.Alert; //引用Alert類 import mx.events.MenuEvent;//MenuEvent類 [Embed(source="flash/bg.swf")]//背景圖形綁定到bgswf private var bgSWF:Class; //簡單編輯器,讀取文件,選擇文件,寫文件的實現 private var fileAll:FileFilter=new FileFilter("*.*","*.*"); //文件過濾,允許打開All private var txtFilter:FileFilter=new FileFilter("*.txt","*.txt"); //文件過濾,只允許打開txt private var jpgFilter:FileFilter=new FileFilter("*.jpg","*.jpg");//文件過濾,只允許打開jpg private var gifFilter:FileFilter=new FileFilter("*.gif","*.gif");//文件過濾,只允許打開gif private var bmpFilter:FileFilter=new FileFilter("*.bmp","*.bmp");//文件過濾,只允許打開bmp private var pngFilter:FileFilter=new FileFilter("*.png","*.png");//文件過濾,只允許打開png private var docFilter:FileFilter=new FileFilter("*.doc","*.doc");//文件過濾,只允許打開doc private var dlgFile:File=new File(); //定義一個File類實例 //選擇文件後讀取文件數據的方法 private function selectHandle(e:Event):void { var file:File=e.target as File; //獲得文件 txtFilePath.text=file.nativePath; //顯示文件路徑 //定義FileStream類實例,用以處理文件流 var stream:FileStream=new FileStream(); stream.open(file, FileMode.READ); //以讀的方式打開文件 //讀取文件中的內容 txtContent.text=stream.readUTFBytes(stream.bytesAvailable); stream.close(); //關閉文件流 } //修改文件內容並寫入到指定文件中的方法 private function modifyText():void { var fileWrite:File=new File(txtFilePath.text); //獲取文件 var streamWrite:FileStream= new FileStream(); //定義FileStream類實例,用以處理文件流 streamWrite.open(fileWrite, FileMode.WRITE);//以寫的方式打開文件 streamWrite.writeUTFBytes(txtContent.text);//寫入到文件流中 Alert.show("修改成功"); //提示修改成功 streamWrite.close();//關閉寫文件流 } //ActionScript調用JavaScript函數返回字符串 private function invokeJavaScript():void { lblResult.text="調用成功!"+txtName.text; } //初始化組件列表 private function initListApp():void { list1.dataProvider=['蘋果','橘子','菠蘿','香蕉','番茄','芒果','龍眼'];//初始化左列表的項 list2.dataProvider=['寶馬','奔馳','奧迪','大衆'];//初始化右列表的項 } //簡單瀏覽器,集成網頁 private function gotoURL():void { html.location="http://"+txtURL.text;//改變html組件的鏈接地址 } private var fb:File=new File("e:/"); private var bk:File=fb.parent; //定義柱狀圖數據集,,內容爲每月收支情況 [Bindable]//對綁定數組是必須的關鍵字 private var finance:ArrayCollection=new ArrayCollection([ {Month:"一", In:2000, Out:1500}, {Month:"二", In:1000, Out:200}, {Month:"三", In:1500, Out:200}, {Month:"四", In:3500, Out:1000}, {Month:"五", In:500, Out:800}, {Month:"六", In:4500, Out:600}, {Month:"七", In:2000, Out:500}, {Month:"八", In:1570, Out:300}, {Month:"九", In:1200, Out:400}, {Month:"十", In:1500, Out:450}, {Month:"十一", In:1700, Out:2500}, {Month:"十二", In:1900, Out:1500}, ]); //定義餅狀圖數據集,,內容爲每月收支情況 [Bindable]//對綁定數組是必須的關鍵字 private var itProgrammer:ArrayCollection=new ArrayCollection([ {itlang:"Java",cout:46.7}, {itlang:"C",count:22.4}, {itlang:"C++",count:14.9}, {itlang:"PHP",count:8.2}, {itlang:"C#",count:3.6}, {itlang:"Python",count:2.5}, {itlang:"Ruby",count:1.7} ]); private function displayCount(data:Object, field:String, index:Number, precentValue:Number):String { var temp:String=(""+precentValue).substr(0,2); return data.itlang+":"+data.count+temp+"%"; } private function loginHandle():void //登陸事件方法 { if(txtUsername.text==""|| txtPassword.text=="") { if(txtUsername.text==""&& txtPassword.text!="") { Alert.show("用戶名不能爲空"); } if(txtPassword.text==""&& txtUsername.text!="") { Alert.show("密碼不能爲空"); } if(txtPassword.text==""&& txtUsername.text=="") { Alert.show("用戶名和密碼不能爲空"); } } else { if(txtUsername.text==loginXML.item.@name && txtPassword.text==loginXML.item.@pass && txtCheck.text.toLowerCase()==codeLabel.text.toLowerCase()) { Alert.show("登陸成功!"); currentState="index"; } if(txtUsername.text==loginXML.item.@name && txtPassword.text==loginXML.item.@pass && txtCheck.text=="") { Alert.show("校驗碼不能爲空!"); } if(txtUsername.text==loginXML.item.@name && txtPassword.text==loginXML.item.@pass && txtCheck.text!="" && txtCheck.text.toLowerCase() != codeLabel.text.toLowerCase()) { Alert.show("您輸的校驗碼有誤!"); //重新生成檢驗碼 initApp(); } if(txtUsername.text!=loginXML.item.@name || txtPassword.text!=loginXML.item.@pass ) { Alert.show("用戶名或密碼錯誤!"); } } } private function resetHandle():void //重置事件方法 { txtUsername.text=""; txtPassword.text=""; txtCheck.text=""; } private function initApp():void //登陸檢驗碼初始化函數 { //顯示檢驗碼 codeLabel.text=generateCheckCode(); } private function generateCheckCode():String //生成四位檢驗碼函數 { //初始化 var ran:Number; var number:Number; var code:String; var checkCode:String=""; //生成四位隨機數 for(var i:int=0; i<4; i++) { ran=Math.random();//生成random()數字類似爲0.1234 number=Math.round(ran*10000);//round()方法四捨五入 if(number%2 ==0)//如果是偶數生成一個數字 { //"0"的ASCII碼是48 code=String.fromCharCode(48+(number%10)); } else //生成一個字母 { //"A"的ASCII碼是65 code=String.fromCharCode(65+(number%26)); } checkCode+= code; } return checkCode; } private function menuClickHandle(e:MenuEvent):void {//MenuEvent類型的"label"屬性可讀取菜單項的內容 if(e.label=="WipeDown") currentState="index1"; //單擊"new"時切換到"index1" else if(e.label=="WipeUp") currentState="index2"; else if(e.label=="WipeLeft") currentState="index3"; else if(e.label=="WipeRight") currentState="index4"; else if(e.label=="Blur") currentState="index5"; else if(e.label=="imageBlur") currentState="blurIndex"; else if(e.label=="Dissolve") currentState="dissolveIndex"; else if(e.label=="Fade") currentState="fadeIndex"; else if(e.label=="imageResize") currentState="resizeIndex"; else if(e.label=="imageRotate") currentState="rotateIndex"; else if(e.label=="soundEffect") currentState="soundIndex"; else if(e.label=="ColumnChart") currentState="columnIndex"; else if(e.label=="PieChart") currentState="piechartIndex"; else if(e.label=="zoomImage") currentState="zoomIndex"; else if(e.label=="filterEg") currentState="filterIndex"; else if(e.label=="SWF") currentState="swfIndex"; else if(e.label=="fileBrowser") currentState="fileIndex"; else if(e.label=="internetExplorer") currentState="IEindex"; else if(e.label=="txtEditor") currentState="txtEditorIndex"; else if(e.label=="AStoJS") currentState="AStoJSIndex"; else if(e.label=="dragList") currentState="dragIndex"; } ]]> </mx:Script> <mx:XML id="loginXML" xmlns=""> <items> <item name="admin" pass="123456"/> </items> </mx:XML> <mx:XMLList id="myXMLList" xmlns=""> <menuitem id="Effect"> <menuitem id="WipeDown" type="radio" groupName="one"/> <menuitem id="WipeUp" type="radio" groupName="one"/> <menuitem id="WipeLeft" type="radio" groupName="one"/> <menuitem id="WipeRight" type="radio" groupName="one"/> <menuitem id="Blur" type="radio" groupName="one"/> <menuitem id="imageBlur" type="radio" groupName="one"/> <menuitem id="Dissolve" type="radio" groupName="one"/> <menuitem id="Fade" type="radio" groupName="one"/> <menuitem id="imageResize" type="radio" groupName="one"/> <menuitem id="imageRotate" type="radio" groupName="one"/> <menuitem id="soundEffect" type="radio" groupName="one"/> </menuitem> <menuitem id="Charts_Others"> <menuitem id="ColumnChart" type="radio" groupName="two"/> <menuitem id="PieChart" type="radio" groupName="two"/> <menuitem id="zoomImage" type="radio" groupName="two"/> <menuitem id="SWF" type="radio" groupName="two"/> <menuitem id="filterEg" type="radio" groupName="two"/> </menuitem> <menuitem id="Tools"> <menuitem id="fileBrowser" type="radio" groupName="three"/> <menuitem id="internetExplorer" type="radio" groupName="three"/> <menuitem id="txtEditor" type="radio" groupName="three"/> <menuitem id="AStoJS" type="radio" groupName="three"/> <menuitem id="dragList" type="radio" groupName="three"/> </menuitem> <menuitem id="Windows"> <menuitem id="Componets" type="radio" groupName="four"/> <menuitem id="Project" type="radio" groupName="four"/> <menuitem id="Navigator" type="radio" groupName="four"/> <menuitem id="Problems" type="radio" groupName="four"/> <menuitem id="Debug" type="radio" groupName="four"/> <menuitem id="State" type="radio" groupName="four"/> </menuitem> </mx:XMLList> </mx:WindowedApplication>
FLV播放器的源代碼:(Cairngorm框架的應用這裏限於篇幅就不貼上來了,也請下載附件)
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:view="com.xi.flvPlayer.view.*" xmlns:control="com.xi.flvPlayer.control.*" layout="absolute" width="624" height="458" showFlexChrome="false" creationComplete="initApp();"> <mx:Script> <![CDATA[ import mx.events.SliderEvent; import mx.controls.sliderClasses.Slider; import com.xi.flvPlayer.event.*; import mx.events.MenuEvent; import flash.filesystem.File; import com.xi.flvPlayer.model.FlvModel; import com.xi.flvPlayer.commands.*; import com.xi.flvPlayer.control.*; import com.xi.flvPlayer.utils.*; import com.xi.flvPlayer.view.FlvPlayerViewHelper; import com.adobe.cairngorm.control.CairngormEventDispatcher; import mx.core.Application; private var displayTypes:FileFilter=new FileFilter("播放格式(*.flv)","*.flv");//定義FileFilter實例 private var allTypes:FileFilter=new FileFilter("全部(*.*)","*.*");//定義FileFilter類的實例 //定義數組fileFilter,表示支持的文件格式 private var fileFilter:Array=new Array(displayTypes,allTypes); //定義File的實例,用以存儲打開的文件 private var choosedFile:File=new File(); //應用程序初始化處理函數 private function initApp():void {//添加鍵盤快捷鍵的監聽 WindowedApplication(mx.core.Application.application).addEventListener (KeyboardEvent.KEY_DOWN,KeyboardClickHandle); var timer:Timer=new Timer(100,0);//添加定時器,設置時間爲100ms timer.addEventListener(TimerEvent.TIMER,checkFocusHandle);//爲定時器的TIMER狀態添加監聽 timer.start();//定時器開始工作 } public function checkFocusHandle(e:TimerEvent):void//定時設置焦點 { WindowedApplication(mx.core.Application.application).setFocus();//設置焦點 } public function KeyboardClickHandle(e:KeyboardEvent):void//快捷鍵處理函數 { switch(e.keyCode) { case 32: //空格按下,則暫停或播放 toggle(); break; case 83: //按下"S"時停止播放 stopPlay(); break; case 113: //按下"s"時停止播放 stopPlay(); break; } } //菜單項單擊處理函數 private function menuClickHandle(e:MenuEvent):void { if(e.item.@label=="Open") { choosedFile.browse(fileFilter);//打開選擇對話框 choosedFile.addEventListener(Event.SELECT,selectHandle);//添加選擇文件後的監聽 } else if(e.item.@label=="Exit")//退出事件 { WindowedApplication(mx.core.Application.application).close();//退出應用程序 } } //選擇文件後的處理函數 private function selectHandle(e:Event):void { FlvModel.videoSource="file:///"+choosedFile.nativePath;//獲取視頻路徑 var evt:OpenVideoEvent=new OpenVideoEvent();//廣播打開視頻事件 CairngormEv