Skip to main content

Posts

Showing posts from July, 2009

[Flex] pureMVC and Utility-StateMachine (2)

Reference: PureMVC AS3 Utility - StateMachine 補充講解一下 StateMachine 是怎樣運作的。 public class StateMachine extends Mediator 打開它的原始碼就可以清楚看到它是一個 Mediator,其實整個機制就是像轉接器,收到 StateMachine.ACTION 通知後,就自動轉到對應的 State 然後利用 sendNotification(); 將新的通知轉發出去,所以它統一的 Notification 寫法就是: sendNotification( StateMachine.ACTION , data , "Your_State_Action_String" ); 然後它就會轉發 sendNotification( "Your_State_Exiting/Entering/Changed_String" , data ); 在 InjectFSMCommand.as 內使用 XML 來宣告 State <state name="Your_State" exiting="Exiting_Notification_Name" entering="Entering_Notification_Name" changed="Changed_Notification_Name"></state> 用法跟一般 Command or Mediator 處理 Notifications 一樣,將 exiting , entering , changed 狀態分別註冊到 Command 又或者直接在 Mediator 內處理通知。

[Flex] pureMVC and Utility - StateMachine

目前手上的 Flex 專案幾乎都是使用 pureMVC 的架構來開發,用到現在還是沒有發現什麼大的缺點,嚴格說起來還挺好用的。組合好心人分享的 pureMVC 工具包也相當好玩。除了自己寫的工具外,目前最愛用的便是 Neil Manuell (project owner) 所分享的 Utility - AS3 StateMachine ,小型專案只需要配合這個就非常完美了~~ 在 Application 的 MXML 中使用 ViewStack 來控制場景變換,是很直覺的作法。但如果你專案還有擴充的空間,這樣做場景到最後你一定後悔!因為可能不是每個 View 都會被新增到 同一個地方。以下是一個簡單的範例講解 pureMVC + StateMachine 的應用。 範例的 Classes tree 開始前請先下載以下的 library:為了方便開發,統一使用 multicore 版本 PureMVC MultiCore for AS3 Utility - AS3 StateMachine 使用 swc 的話請直接將 .swc 檔放置到 libs/ 內,如果是下載 class 的話,請放置到 src/ 中 範例場景說明: Application MXML 中有個 tab bar 點選後會換場景 Shop <-> Shop1 ( 當然場景可以無限新增,這只是個範例...) pureMVCAndStateMachine.mxml <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="init()" layout="vertical"> <mx:Script> <![CDATA[ import mx.events.ItemClickEvent; import com.mvc.ApplicationFacade; private function init():void{ ApplicationFacade