Skip to main content

Posts

Showing posts from August, 2009

[AS3] pureMVC Utility - WidgetsConsole 1.0.0

Project Name: pureMVC Utility - WidgetsConsole Version: 1.0.0 Project Owner: Erin Lin Description: An utility is under pureMVC Multicore that has Flex only and AS3 two versions. Demo: WidgetsConsole Live Demo with source code Demo source code Download: WidgetsConsole Open Source Project Home pureMVC website: http://puremvc.org/ 沒想到我第一個 google code open source project 就獻給 pureMVC 了... 套用 pureMVC 到 Flex 專案第一個遇到的問題就是 view components 的控制,Flex 專案的 view 總類太多:有 Modules, UIComponent, external swf and pop-up view...etc. 整個專案作下來光 view 就可能換上幾十個頁面,先前分享了運用 StateMachine 來處理 view 的轉換,中大型專案作下來 code 的複雜度也是非常可觀。我在今年二月分享了 [Flex] pureMVC MultiCore with Modules 就開始著手將其概念包裝成 pureMVC 的工具包,使用到目前為止整個架構還是挺完善,所以在這邊與大家分享。 WdigetConsole 顧名思義是「 相同目的 views 組合 = Widget 」 的中央控制中心,將程式內加入 WidgetsConsole 的 widget 統一控管,最終只需要 sendNotification 就可以達到 view 的新增跟刪除(因為我是懶人工具的愛好者,懶人工具的定義就是以最低的限度達到所需要的效果,所以這個工具包的自由度很高!) 以下是簡單講解 WidgetsConsole 是什麼: Widget 的定義: View component(s) + WidgetMediator + WidgetCommand 實作的 WidgetCommand:

[pureMVC] Flex app 開發的心得分享

使用 pureMVC 開發到現在,也遇到不少網友詢問相關問題,以下是 Erin 整理的幾個使用 pureMVC framework 開發 Flex app 的心得分享: 雖然 pureMVC Standard 版本就很夠用了,但是你的 app 有未知擴充需求的話還是建議使用 Mulitcore 版本以達最大的開發彈性。 先問問自己能不能理解架構內 Notification and Command 是什麼作用?如果答案是『NO』,請先熟悉 pureMVC 的架構再行考量是不是要實作...因為有太多問題都可以利用它們解決。 先搞清楚你將要開發的 app 流程,花點時間研究官網上的 pureMVC Utilities,一定有工具包可以解決你的需求。 除了 Application 外 view component 不應該持有任何跟 pureMVC 有關的 Class instance reference,請善用 Flex & Flash Event 機制與外部溝通。 別把 view component 直接對 view component 溝通的開發邏輯帶到架構內,如果你還是打算這樣作就根本不需要使用任何 framework 來幫助開發! View componet 溝通邏輯應該是 A-view component -> Event -> A-Mediator -> Notification -> Proxy, Command or B-Mediator -> B-view component。Event 機制在這邊有很大的作用,Mediator "儘量"不持有 view componet 子物件只接收其 Event ,不僅可以讓你跳脫如何用 A view 控制 B view 的思維...因為 A view 根本不需要去知道它發了 Event 後誰會被控制; 對 view component 新增修改也比較容易,ex. view component 由 Flex 3 改 Flex 4 版本(尤其 Flex 4 的架構改很大...你就會發現用 Event 的重要性...) Mediator 要 override onRegister and onRemove function,做人要有始有終,請記得 EventL

[AS3] 簡單講客製 Event (2)

一般的使用只需要繼承自 flash.events.Event, 並且覆寫 clone 這個 function package events { import flash.events.Event; public class CustomEvent extends Event { public var data:Object; // 喜歡什麼都可以自己加~~當然也可以用 getter & setter 宣告 public function CustomEvent( type:String , data:Object ) { super(type); this.data = data; } override public function clone():Event { return new CustomEvent( type , data ); } } } 如果你的 Event 需要 bubbles 請修改: super( type , true ) 方便 debug 版本,就是多一個覆寫 toString function package events { import flash.events.Event; public class Custom2Event extends Event { public var output:String; public static const UPDATE_OUTPUT:String = "update_output"; public function Custom2Event( type:String , output:String) { super(type); this.output = output; } override public function clone():Event { return new Custom2Event( type , output ); } override public function toString():String { //印出你想要看的資訊 return formatToString("Custom2Event"