終于把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([email protected] &&
[email protected] &&
txtCheck.text.toLowerCase()==codeLabel.text.toLowerCase())
{
Alert.show("登陸成功!");
currentState="index";
}
if([email protected] &&
[email protected] &&
txtCheck.text=="")
{
Alert.show("校驗碼不能為空!");
}
if([email protected] &&
[email protected] &&
txtCheck.text!="" && txtCheck.text.toLowerCase()
!= codeLabel.text.toLowerCase())
{
Alert.show("您輸的校驗碼有誤!");
//重新生成檢驗碼
initApp();
}
if([email protected] ||
[email protected] )
{
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([email protected]=="Open")
{
choosedFile.browse(fileFilter);//打開選擇對話框
choosedFile.addEventListener(Event.SELECT,selectHandle);//添加選擇檔案後的監聽
}
else if([email protected]=="Exit")//退出事件
{
WindowedApplication(mx.core.Application.application).close();//退出應用程式
}
}
//選擇檔案後的處理函數
private function selectHandle(e:Event):void
{
FlvModel.videoSource="file:///"+choosedFile.nativePath;//擷取視訊路徑
var evt:OpenVideoEvent=new OpenVideoEvent();//廣播打開視訊事件
CairngormEv