Skip to main content

[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 內處理通知。

Comments

Popular posts from this blog

[書評] 拖延心理學:為什麼我老是愛拖延?是與生俱來的壞習慣,還是身不由己?

作者: Jane B. Burka & Lenora M . Yuen 推薦指數 ★★★★★ 有時候,只是想了解事情發生原因而不是尋求解法 在這邊不是要講這本書的內容,而是想聊它對我的影響。