PageRenderTime 1157ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Main.as

http://flash-state-engine.googlecode.com/
ActionScript | 617 lines | 479 code | 109 blank | 29 comment | 16 complexity | 5acd3d2e345615026c44ed2104648765 MD5 | raw file
  1. /*
  2. /**
  3. * This is an example of instantiating the various parts of the state engine.
  4. * The actual state machine is nonsense -- the purpose of the example is to show
  5. * how things fit together. It was created using FlashDevelop 3.0.
  6. */
  7. package
  8. {
  9. import com.flashsim.FStEng.Three.Transition;
  10. import flash.display.Sprite;
  11. import flash.display.MovieClip;
  12. import com.flashsim.FStEng.Three.HState;
  13. import com.flashsim.FStEng.Three.HStateC;
  14. import com.flashsim.FStEng.Three.State;
  15. import com.flashsim.FStEng.Three.StateManager;
  16. import flash.events.Event;
  17. import com.flashsim.FStEng.Three.StateEngine;
  18. import com.flashsim.FStEng.Three.EventWithData;
  19. import com.flashsim.FStEng.Three.PulseActivity;
  20. import flash.utils.getTimer;
  21. public class Main extends Sprite
  22. {
  23. public var se:StateEngine;
  24. private var FirstMachineOutput:Array = ["******** ENGINE EVENT ACTIVATE",
  25. "WE ENTERED state <TOP_CONTAINER_STATE>",
  26. "WE ENTERED state <ON>",
  27. "WE ENTERED state <ON 0>",
  28. "WE ENTERED state <ON5>",
  29. "State <ON 0> Caught event: RANDOM",
  30. "FINISHED POSTING EVENTS",
  31. "PULSE <ON 0>",
  32. "State <ON5> Caught event: RANDOM5",
  33. "WE LEFT state <ON 0>",
  34. "ON 0 -> ON1 on Event: RANDOM5",
  35. "WE ENTERED state <ON1>",
  36. "WE LEFT state <ON1>",
  37. "ON1 -> ON2 on Event: BOOGA-BOOGA",
  38. "WE ENTERED state <ON2>",
  39. "WE LEFT state <ON2>",
  40. "WE LEFT state <ON5>",
  41. "WE LEFT state <ON>",
  42. "ON2 transition to OFF 0, Event: AFTER BOOGA-BOOGA",
  43. "WE ENTERED state <OFF>",
  44. "WE ENTERED state <OFF0>",
  45. "WE LEFT state <OFF0>",
  46. "WE LEFT state <OFF>",
  47. "topContainerState transition to ON's History, Event: REALLY AFTER AFTER BOOGA-BOOGA",
  48. "WE ENTERED state <ON>",
  49. "WE ENTERED state <ON2>",
  50. "WE ENTERED state <ON5>",
  51. "WE LEFT state <ON2>",
  52. "WE LEFT state <ON5>",
  53. "WE LEFT state <ON>",
  54. "WE LEFT state <TOP_CONTAINER_STATE>",
  55. "******** ENGINE EVENT DEACTIVATE",
  56. "EVENT NOT HANDLED: [Event type=\"TEST COMPLETE\" bubbles=false cancelable=false eventPhase=2]"
  57. ];
  58. private var OutputLog:Array;
  59. private var SamekTestOutput:Array = ["WE ENTERED state <s0>",
  60. "WE ENTERED state <s1>",
  61. "WE ENTERED state <s11>",
  62. "POSTING EVENT (A)",
  63. "WE LEFT state <s11>",
  64. "WE LEFT state <s1>",
  65. "WE ENTERED state <s1>",
  66. "WE ENTERED state <s11>",
  67. "POSTING EVENT (B)",
  68. "POSTING EVENT (C)",
  69. "WE LEFT state <s11>",
  70. "WE LEFT state <s1>",
  71. "WE ENTERED state <s2>",
  72. "WE ENTERED state <s21>",
  73. "WE ENTERED state <s211>",
  74. "POSTING EVENT (D)",
  75. "WE LEFT state <s211>",
  76. "WE ENTERED state <s211>",
  77. "POSTING EVENT (E)",
  78. "POSTING EVENT (F)",
  79. "WE LEFT state <s211>",
  80. "WE LEFT state <s21>",
  81. "WE LEFT state <s2>",
  82. "WE ENTERED state <s1>",
  83. "WE ENTERED state <s11>",
  84. "POSTING EVENT (G)",
  85. "WE LEFT state <s11>",
  86. "WE LEFT state <s1>",
  87. "WE ENTERED state <s2>",
  88. "WE ENTERED state <s21>",
  89. "WE ENTERED state <s211>",
  90. "POSTING EVENT (G)",
  91. "FINISHED TEST",
  92. "WE LEFT state <s211>",
  93. "WE LEFT state <s21>",
  94. "WE LEFT state <s2>",
  95. "WE LEFT state <s0>",
  96. "EVENT NOT HANDLED: [Event type=\"TEST COMPLETE\" bubbles=false cancelable=false eventPhase=2]"
  97. ];
  98. private var allTransTypesOutput:Array = ["******** ENGINE EVENT ACTIVATE",
  99. "WE ENTERED state <s0>",
  100. "WE ENTERED state <s1>",
  101. "WE ENTERED state <s10>",
  102. "POSTING EVENT (a1)",
  103. "WE LEFT state <s10>",
  104. "WE ENTERED state <s10>",
  105. "POSTING EVENT (a2)",
  106. "WE LEFT state <s10>",
  107. "WE LEFT state <s1>",
  108. "WE ENTERED state <s1>",
  109. "WE ENTERED state <s10>",
  110. "POSTING EVENT (b1)",
  111. "WE LEFT state <s10>",
  112. "WE ENTERED state <s11>",
  113. "POSTING EVENT (c)",
  114. "EVENT NOT HANDLED: [Event type=\"c\" bubbles=false cancelable=false eventPhase=2]",
  115. "POSTING EVENT (d)",
  116. "WE LEFT state <s11>",
  117. "WE LEFT state <s1>",
  118. "WE ENTERED state <s1>",
  119. "WE ENTERED state <s10>",
  120. "POSTING EVENT (e)",
  121. "WE LEFT state <s10>",
  122. "WE ENTERED state <s11>",
  123. "POSTING EVENT (b2)",
  124. "WE LEFT state <s11>",
  125. "WE ENTERED state <s10>",
  126. "POSTING EVENT (f)",
  127. "WE LEFT state <s10>",
  128. "WE LEFT state <s1>",
  129. "WE ENTERED state <s2>",
  130. "WE ENTERED state <s21>",
  131. "POSTING EVENT (g)",
  132. "WE LEFT state <s21>",
  133. "WE LEFT state <s2>",
  134. "WE ENTERED state <s3>",
  135. "WE ENTERED state <s300>",
  136. "WE ENTERED state <s310>",
  137. "WE ENTERED state <s320>",
  138. "POSTING EVENT (b3)",
  139. "WE LEFT state <s320>",
  140. "WE ENTERED state <s321>",
  141. "WE LEFT state <s310>",
  142. "WE ENTERED state <s311>",
  143. "WE LEFT state <s300>",
  144. "WE ENTERED state <s301>",
  145. "POSTING EVENT (h)",
  146. "WE LEFT state <s301>",
  147. "WE LEFT state <s311>",
  148. "WE LEFT state <s321>",
  149. "WE LEFT state <s3>",
  150. "WE ENTERED state <s1>",
  151. "WE ENTERED state <s10>",
  152. "POSTING EVENT (i)",
  153. "WE LEFT state <s10>",
  154. "WE LEFT state <s1>",
  155. "WE ENTERED state <s3>",
  156. "WE ENTERED state <s310>",
  157. "WE ENTERED state <s320>",
  158. "WE ENTERED state <s301>",
  159. "POSTING EVENT (h)",
  160. "WE LEFT state <s301>",
  161. "WE LEFT state <s310>",
  162. "WE LEFT state <s320>",
  163. "WE LEFT state <s3>",
  164. "WE ENTERED state <s1>",
  165. "WE ENTERED state <s10>",
  166. "POSTING EVENT (j)",
  167. "WE LEFT state <s10>",
  168. "WE LEFT state <s1>",
  169. "WE ENTERED state <s3>",
  170. "WE ENTERED state <s301>",
  171. "WE ENTERED state <s310>",
  172. "WE ENTERED state <s320>",
  173. "POSTING EVENT (b3)",
  174. "WE LEFT state <s320>",
  175. "WE ENTERED state <s321>",
  176. "WE LEFT state <s310>",
  177. "WE ENTERED state <s311>",
  178. "POSTING EVENT (k)",
  179. "WE LEFT state <s321>",
  180. "WE ENTERED state <s320>",
  181. "FINISHED TEST",
  182. "WE LEFT state <s301>",
  183. "WE LEFT state <s311>",
  184. "WE LEFT state <s320>",
  185. "WE LEFT state <s3>",
  186. "WE LEFT state <s0>",
  187. "******** ENGINE EVENT DEACTIVATE",
  188. "EVENT NOT HANDLED: [Event type=\"TEST COMPLETE\" bubbles=false cancelable=false eventPhase=2]"
  189. ];
  190. private var tests:Array = [SamekTest, FirstMachine, allTransTypes ];
  191. private var testLogs:Array = [SamekTestOutput, FirstMachineOutput, allTransTypesOutput ];
  192. private var testLog:Array;
  193. private var testNames:Array = ["SAMEK TEST", "FIRST MACHINE", "ALL TRANSITION JUMPS"];
  194. private var currentTest:int = 0;
  195. private var numberOfTests:int = 3;
  196. public function Main():void
  197. {
  198. // ****************************************
  199. // Define state engine and network.
  200. // This is an example of declaring the topmost state in the StateEngine definition.
  201. OutputLog = [];
  202. testLog = testLogs[currentTest];
  203. trace("> RUNNING TEST " + testNames[currentTest]);
  204. tests[currentTest]();
  205. }
  206. private function finishTest () : void {
  207. var clean:Boolean = true, i:int = 0, failPt:int = 0;
  208. for (i = 0; i < testLog.length && i < OutputLog.length; i++) {
  209. if (OutputLog[i] != testLog[i]) {
  210. trace("** MACHINE TEST FAIL\n", "SHOULD BE: " + testLog[i] + "\nBUT OUTPUT IS: " + OutputLog[i] + "\n");
  211. clean = false;
  212. break;
  213. }
  214. }
  215. if (testLog.length != OutputLog.length) {
  216. trace("CURRENT LOG AND CORRECT LOG HAVE DIFFERENT # OF ELEMENTS.");
  217. clean = false;
  218. }
  219. if (clean) {
  220. trace("< PASSED: " + testNames[currentTest]);
  221. currentTest++;
  222. if (currentTest < numberOfTests) {
  223. OutputLog = [];
  224. trace("> RUNNING TEST " + testNames[currentTest]);
  225. testLog = testLogs[currentTest];
  226. tests[currentTest]();
  227. } else {
  228. trace("*** ALL TESTS COMPLETED SUCCESSFULLY.");
  229. }
  230. } else {
  231. failPt = i;
  232. trace(testNames[currentTest] + " FAILED\n", ">>>> HERE IS CURRENT LOG FROM FAILURE POINT:");
  233. for (; i < OutputLog.length; i++) {
  234. trace(" " + OutputLog[i]);
  235. }
  236. trace(">>>> HERE IS CORRECT LOG FROM FAILURE POINT:");
  237. for (i=failPt; i < testLog.length; i++) {
  238. trace(" " + testLog[i]);
  239. }
  240. }
  241. }
  242. private function addToLog (s:String) : void {
  243. OutputLog.push(s);
  244. }
  245. /* ******************************************************************* */
  246. public function EnterExitState (ev:Event) : void {
  247. addToLog("WE " + (ev.type == "ENTRY" ? "ENTERED" : "LEFT") + " state <" + State(ev.target).name + ">");
  248. }
  249. public function NoHandle (ev:Event) : void {
  250. var givenEvent:Event = EventWithData(ev).data.event;
  251. if (givenEvent.type == "TEST COMPLETE") {
  252. se.active = false;
  253. addToLog("EVENT NOT HANDLED: " + givenEvent);
  254. finishTest();
  255. } else {
  256. addToLog("EVENT NOT HANDLED: " + givenEvent);
  257. }
  258. }
  259. public function EngineActive (ev:Event) : void {
  260. addToLog("******** ENGINE EVENT " + ev.type);
  261. }
  262. /* ******************************************************************* */
  263. private function SamekTest () : void {
  264. // Samek Engine test
  265. se = new StateEngine("Samek02 Fig 4.3", new HState("s0"));
  266. se.addEventListener(StateEngine.UNHANDLED_EVENT, NoHandle);
  267. // Retrieving and storing the pointer to the topmost state
  268. var s0:HState = HState(se.topState);
  269. s0.setDefaultStartState("s1");
  270. s0.addEventListener(State.ENTRY, EnterExitState);
  271. s0.addEventListener(State.LEAVE, EnterExitState);
  272. s0.addTransitionToTarget("Evt_e", "s211");
  273. // Set up a handler for events that go unhandled
  274. var s1:HState = s0.addSubHState("s1");
  275. s1.setDefaultStartState("s11");
  276. s1.addEventListener(State.ENTRY, EnterExitState);
  277. s1.addEventListener(State.LEAVE, EnterExitState);
  278. s1.addTransitionToSelf("Evt_a", null, 0);
  279. s1.addTransitionToTarget("Evt_b", "s11");
  280. s1.addTransitionToTarget("Evt_c", "s2");
  281. var s11:State = s1.addSubState("s11");
  282. s11.addEventListener(State.ENTRY, EnterExitState);
  283. s11.addEventListener(State.LEAVE, EnterExitState);
  284. s11.addTransitionToTarget("Evt_g", "s211");
  285. var s2:HState = s0.addSubHState("s2");
  286. s2.setDefaultStartState("s21");
  287. s2.addEventListener(State.ENTRY, EnterExitState);
  288. s2.addEventListener(State.LEAVE, EnterExitState);
  289. s2.addTransitionToTarget("Evt_f", "s11");
  290. var s21:HState = s2.addSubHState("s21");
  291. s21.setDefaultStartState("s211");
  292. s21.addEventListener(State.ENTRY, EnterExitState);
  293. s21.addEventListener(State.LEAVE, EnterExitState);
  294. var s211:State = s21.addSubState("s211");
  295. s211.addTransitionToTarget("Evt_d", "s21");
  296. s211.addTransitionToTarget("Evt_g", "s0");
  297. s211.addEventListener(State.ENTRY, EnterExitState);
  298. s211.addEventListener(State.LEAVE, EnterExitState);
  299. se.active = true;
  300. addToLog("POSTING EVENT (A)");
  301. se.postEvent(new Event("Evt_a"));
  302. addToLog("POSTING EVENT (B)");
  303. se.postEvent(new Event("Evt_b"));
  304. addToLog("POSTING EVENT (C)");
  305. se.postEvent(new Event("Evt_c"));
  306. addToLog("POSTING EVENT (D)");
  307. se.postEvent(new Event("Evt_d"));
  308. addToLog("POSTING EVENT (E)");
  309. se.postEvent(new Event("Evt_e"));
  310. addToLog("POSTING EVENT (F)");
  311. se.postEvent(new Event("Evt_f"));
  312. addToLog("POSTING EVENT (G)");
  313. se.postEvent(new Event("Evt_g"));
  314. addToLog("POSTING EVENT (G)");
  315. addToLog("FINISHED TEST");
  316. se.postEvent(new Event("TEST COMPLETE"));
  317. }
  318. private function FirstMachine () : void {
  319. /*
  320. Initial machine test
  321. */
  322. se = new StateEngine("engine1", new HState("TOP_CONTAINER_STATE"));
  323. // Register handlers to react to StateEngine activation and deactivation
  324. se.addEventListener(StateEngine.ACTIVATE, EngineActive);
  325. se.addEventListener(StateEngine.DEACTIVATE, EngineActive);
  326. // Set up a handler for events that go unhandled
  327. se.addEventListener(StateEngine.UNHANDLED_EVENT, NoHandle);
  328. // Retrieving and storing the pointer to the topmost state
  329. var topContainerState:HState = HState(se.topState);
  330. topContainerState.setDefaultStartState("ON");
  331. // Adding transitions and listeners to the topmost state.
  332. topContainerState.addTransitionToHistory("REALLY AFTER AFTER BOOGA-BOOGA", "ON", function ():void { addToLog("topContainerState transition to ON's History, Event: REALLY AFTER AFTER BOOGA-BOOGA"); } ); // If we get event REALLY AFTER AFTER BOOGA-BOOGA, go to state OFF1
  333. topContainerState.addEventListener(State.ENTRY, EnterExitState);
  334. topContainerState.addEventListener(State.LEAVE, EnterExitState);
  335. var offState:HState = topContainerState.addSubHState("OFF");
  336. offState.setDefaultStartState("OFF0");
  337. offState.addTransitionToTarget("BOOGA-BOOGA", "OFF1", function ():void { addToLog("OFF State to OFF1"); } );
  338. offState.addEventListener(State.ENTRY, EnterExitState);
  339. offState.addEventListener(State.LEAVE, EnterExitState);
  340. var off0State:State = offState.addSubState("OFF0");
  341. off0State.addEventListener(State.ENTRY, EnterExitState);
  342. off0State.addEventListener(State.LEAVE, EnterExitState);
  343. off0State.addTransitionToSelf("BOOGA-BOOGA", function ():void { addToLog("OFF0 Transition to Self (up and down 2 levels)"); }, 2); // transition to self
  344. var off1State:State = offState.addSubState("OFF1");
  345. off1State.addEventListener(State.ENTRY, EnterExitState);
  346. off1State.addEventListener(State.LEAVE, EnterExitState);
  347. // Add a time-based pulse activity that fires every 2 seconds, approx.
  348. off1State.addPulseActivity(2000, statePulse);
  349. off1State.addTransitionToTarget("RANDOM", "ON1", function ():void { addToLog("OFF1 -> ON1 on Event: RANDOM"); } );
  350. // Create a concurrent hierarchical state. We will need separate State Managers for each sub-network.
  351. var onState:HStateC = topContainerState.addSubHStateC("ON");
  352. var onMgr0:StateManager = new StateManager("<ON MANAGER 0>", onState);
  353. var onMgr1:StateManager = new StateManager("<ON MANAGER 1>", onState);
  354. onState.setDefaultStartState("ON 0", onMgr0);
  355. onState.setDefaultStartState("ON5", onMgr1);
  356. onState.addEventListener(State.ENTRY, EnterExitState);
  357. onState.addEventListener(State.LEAVE, EnterExitState);
  358. // First sub-network, managed by <ON MANAGER 0>: states 0, 1, and 2
  359. var onState0:State = onState.addSubState("ON 0", onMgr0); // creates a sub-state of onState called ON 0 in the onMgr0 network
  360. onState0.addPulseActivity(40, statePulse, true); // frame-based pulse activity
  361. onState0.addEventListener(State.ENTRY, EnterExitState);
  362. onState0.addEventListener(State.LEAVE, EnterExitState);
  363. onState0.addEventListener("RANDOM", CaughtEvent0);
  364. onState0.addTransitionToTarget("RANDOM5", "ON1", function ():void { addToLog("ON 0 -> ON1 on Event: RANDOM5"); } );
  365. var onState1:State = onState.addSubState("ON1", onMgr0); // creates a sub-state of onState called ON1 in the onMgr0 network
  366. onState1.addTransitionToTarget("BOOGA-BOOGA", "ON2", function ():void { addToLog("ON1 -> ON2 on Event: BOOGA-BOOGA"); } );
  367. onState1.addEventListener(State.ENTRY, EnterExitState);
  368. onState1.addEventListener(State.LEAVE, EnterExitState);
  369. var onState2:State = onState.addSubState("ON2", onMgr0); // creates a sub-state ofonState called ON2 in the onMgr0 network
  370. onState2.addEventListener(State.ENTRY, EnterExitState);
  371. onState2.addEventListener(State.LEAVE, EnterExitState);
  372. onState2.addTransitionToTarget("AFTER BOOGA-BOOGA", "OFF0", function ():void { addToLog("ON2 transition to OFF 0, Event: AFTER BOOGA-BOOGA"); } );
  373. // Second sub-network, managed by <ON MANAGER 1> state 5
  374. var onState5:State = onState.addSubState("ON5", onMgr1); // creates a sub-state of onState called ON5 in the onMgr1 network
  375. onState5.addEventListener(State.ENTRY, EnterExitState);
  376. onState5.addEventListener(State.LEAVE, EnterExitState);
  377. onState5.addEventListener("RANDOM5", CaughtEvent5);
  378. // ****************************************
  379. // activate network and send in some events
  380. se.active = true;
  381. se.postEvent(new Event("RANDOM")); // handled by onState0. During handling, we'll send another event, RANDOM5
  382. se.postEvent(new Event("BOOGA-BOOGA"), 2500); // unhandled, but delayed by 5 seconds
  383. se.postEvent(new Event("AFTER BOOGA-BOOGA"));
  384. se.postEvent(new Event("REALLY AFTER AFTER BOOGA-BOOGA"), 1000);
  385. addToLog("FINISHED POSTING EVENTS");
  386. se.postEvent(new Event("TEST COMPLETE"));
  387. }
  388. public function statePulse (ev:Event) : void {
  389. addToLog("PULSE <" + State(EventWithData(ev).data.state).name + ">");
  390. }
  391. public function CaughtEvent0 (ev:Event) : void {
  392. addToLog("State <" + State(ev.target).name + "> Caught event: " + ev.type);
  393. se.postEvent(new Event("RANDOM5"), 2000); // handled by onState5
  394. }
  395. public function CaughtEvent5 (ev:Event) : void {
  396. addToLog("State <" + State(ev.target).name + "> Caught event: " + ev.type);
  397. }
  398. private function allTransTypes () : void {
  399. se = new StateEngine("allTransTypes", new HState("s0"));
  400. // Register handlers to react to StateEngine activation and deactivation
  401. se.addEventListener(StateEngine.ACTIVATE, EngineActive);
  402. se.addEventListener(StateEngine.DEACTIVATE, EngineActive);
  403. // Set up a handler for events that go unhandled. For test cases, we need this because we handle TEST COMPLETE here.
  404. se.addEventListener(StateEngine.UNHANDLED_EVENT, NoHandle);
  405. var topContainerState:HState = HState(se.topState);
  406. topContainerState.addEventListener(State.ENTRY, EnterExitState);
  407. topContainerState.addEventListener(State.LEAVE, EnterExitState);
  408. topContainerState.setDefaultStartState("s1");
  409. topContainerState.addTransitionToTarget("e", "s11");
  410. var s1:HState = topContainerState.addSubHState("s1");
  411. s1.setDefaultStartState("s10");
  412. s1.addTransitionToHistory("j", "s3");
  413. s1.addTransitionToTarget("i", "s301");
  414. s1.addEventListener(State.ENTRY, EnterExitState);
  415. s1.addEventListener(State.LEAVE, EnterExitState);
  416. var s10:State = s1.addSubState("s10");
  417. s10.addEventListener(State.ENTRY, EnterExitState);
  418. s10.addEventListener(State.LEAVE, EnterExitState);
  419. s10.addTransitionToSelf("a1");
  420. s10.addTransitionToSelf("a2", null, 1);
  421. s10.addTransitionToTarget("b1", "s11");
  422. s10.addTransitionToTarget("f", "s21");
  423. var s11:State = s1.addSubState("s11");
  424. s11.addEventListener(State.ENTRY, EnterExitState);
  425. s11.addEventListener(State.LEAVE, EnterExitState);
  426. s11.addTransitionToTarget("d", "s0");
  427. s11.addTransitionToTarget("b2", "s10");
  428. var s2:HState = topContainerState.addSubHState("s2");
  429. s2.addEventListener(State.ENTRY, EnterExitState);
  430. s2.addEventListener(State.LEAVE, EnterExitState);
  431. s2.setDefaultStartState("s20");
  432. var s20:State = s2.addSubState("s20");
  433. s20.addEventListener(State.ENTRY, EnterExitState);
  434. s20.addEventListener(State.LEAVE, EnterExitState);
  435. var s21:State = s2.addSubState("s21");
  436. s21.addEventListener(State.ENTRY, EnterExitState);
  437. s21.addEventListener(State.LEAVE, EnterExitState);
  438. s21.addTransitionToTarget("g", "s3");
  439. var s3:HStateC = topContainerState.addSubHStateC("s3");
  440. s3.addEventListener(State.ENTRY, EnterExitState);
  441. s3.addEventListener(State.LEAVE, EnterExitState);
  442. s3.addTransitionToTarget("h", "s1");
  443. var s3Mgr0:StateManager = new StateManager("<s3 MGR 0>", s3);
  444. var s300:State = s3.addSubState("s300", s3Mgr0);
  445. s300.addEventListener(State.ENTRY, EnterExitState);
  446. s300.addEventListener(State.LEAVE, EnterExitState);
  447. s300.addTransitionToTarget("b3", "s301");
  448. var s301:State = s3.addSubState("s301", s3Mgr0);
  449. s301.addEventListener(State.ENTRY, EnterExitState);
  450. s301.addEventListener(State.LEAVE, EnterExitState);
  451. s3.setDefaultStartState("s300", s3Mgr0);
  452. var s3Mgr1:StateManager = new StateManager("<s3 MGR 1>", s3);
  453. var s310:State = s3.addSubState("s310", s3Mgr1);
  454. s310.addEventListener(State.ENTRY, EnterExitState);
  455. s310.addEventListener(State.LEAVE, EnterExitState);
  456. s310.addTransitionToTarget("b3", "s311");
  457. var s311:State = s3.addSubState("s311", s3Mgr1);
  458. s311.addEventListener(State.ENTRY, EnterExitState);
  459. s311.addEventListener(State.LEAVE, EnterExitState);
  460. s3.setDefaultStartState("s310", s3Mgr1);
  461. var s3Mgr2:StateManager = new StateManager("<s3 MGR 2>", s3);
  462. s3.setDefaultStartState("s320", s3Mgr2);
  463. var s320:State = s3.addSubState("s320", s3Mgr2);
  464. s320.addEventListener(State.ENTRY, EnterExitState);
  465. s320.addEventListener(State.LEAVE, EnterExitState);
  466. s320.addTransitionToTarget("b3", "s321");
  467. var s321:State = s3.addSubState("s321", s3Mgr2);
  468. s321.addEventListener(State.ENTRY, EnterExitState);
  469. s321.addEventListener(State.LEAVE, EnterExitState);
  470. s321.addTransitionToHistory("k", "s3");
  471. se.active = true;
  472. addToLog("POSTING EVENT (a1)");
  473. se.postEvent(new Event("a1"));
  474. addToLog("POSTING EVENT (a2)");
  475. se.postEvent(new Event("a2"));
  476. addToLog("POSTING EVENT (b1)");
  477. se.postEvent(new Event("b1"));
  478. addToLog("POSTING EVENT (c)");
  479. se.postEvent(new Event("c"));
  480. addToLog("POSTING EVENT (d)");
  481. se.postEvent(new Event("d"));
  482. addToLog("POSTING EVENT (e)");
  483. se.postEvent(new Event("e"));
  484. addToLog("POSTING EVENT (b2)");
  485. se.postEvent(new Event("b2"));
  486. addToLog("POSTING EVENT (f)");
  487. se.postEvent(new Event("f"));
  488. addToLog("POSTING EVENT (g)");
  489. se.postEvent(new Event("g"));
  490. addToLog("POSTING EVENT (b3)");
  491. se.postEvent(new Event("b3"));
  492. addToLog("POSTING EVENT (h)");
  493. se.postEvent(new Event("h"));
  494. addToLog("POSTING EVENT (i)");
  495. se.postEvent(new Event("i"));
  496. addToLog("POSTING EVENT (h)");
  497. se.postEvent(new Event("h"));
  498. addToLog("POSTING EVENT (j)");
  499. se.postEvent(new Event("j"));
  500. addToLog("POSTING EVENT (b3)");
  501. se.postEvent(new Event("b3"));
  502. addToLog("POSTING EVENT (k)");
  503. se.postEvent(new Event("k"));
  504. addToLog("FINISHED TEST");
  505. se.postEvent(new Event("TEST COMPLETE"));
  506. }
  507. }
  508. }