Package | com.yworks.support |
Class | public class StateMachine |
Inheritance | StateMachine flash.events.EventDispatcher |
The machine is built of State
s and Transition
s.
The machine potentially changes its state in response to events.
Property | Defined By | ||
---|---|---|---|
currentState : State
Gets or sets the current state the machine is in. | StateMachine | ||
startState : State [read-only]
Gets the start state. | StateMachine | ||
states : Array [read-only]
Returns all states in this machine. | StateMachine | ||
transitions : Array [read-only]
Returns all transitions in this machine. | StateMachine |
Method | Defined By | ||
---|---|---|---|
StateMachine(transitionDoneHandler:Function = null, stateEnteredHandler:Function = null, startState:State = null)
Creates an empty machine using the provided event listeners and a given start state. | StateMachine | ||
createState(stateEnteredHandler:Function = null):State
Creates a new state given a listener for the stateEntered event. | StateMachine | ||
createTransition(source:State, target:State, eventRecognizer:Function = null, transitionDoneListener:Function = null):Transition
Creates a conditional transition between two given states using a given transitionDone listener. | StateMachine | ||
Finds a transistion that connects two given states. | StateMachine | ||
performTransition(transition:Transition):void
Executes a given transition programmatically, regardless whether this
is currently allowed. | StateMachine | ||
removeState(state:State):void
Removes a state from this machine. | StateMachine | ||
removeTransition(transition:Transition):void
Removes a transition from this state machine. | StateMachine | ||
reset():void
Resets this machine so that the current state is the startState. | StateMachine | ||
run(evt:Event):void
Runs this machine using the given event source and event argument
to determine which transition to take from the currentState. | StateMachine |
Method | Defined By | ||
---|---|---|---|
Called when the current state changes. | StateMachine | ||
onTransition(transition:Transition):void
Called when a transition is being traversed. | StateMachine |
Event | Summary | Defined By | ||
---|---|---|---|---|
An event that will be triggerd if a state has been created. | StateMachine | |||
Dispatched when a state has been entered during a run call. | StateMachine | |||
Dispatched when a state has been exited during a run call. | StateMachine | |||
An event that will be triggerd if a state has been removed. | StateMachine | |||
Dispatched when a transition has been created. | StateMachine | |||
Dispatched when the statemachine has traversed a Transition during a run call. | StateMachine | |||
Dispatched when a transition has been removed. | StateMachine |
currentState | property |
currentState:State
Gets or sets the current state the machine is in.
public function get currentState():State
public function set currentState(value:State):void
startState | property |
startState:State
[read-only] Gets the start state.
public function get startState():State
states | property |
states:Array
[read-only] Returns all states in this machine.
public function get states():Array
transitions | property |
transitions:Array
[read-only] Returns all transitions in this machine.
public function get transitions():Array
StateMachine | () | Constructor |
public function StateMachine(transitionDoneHandler:Function = null, stateEnteredHandler:Function = null, startState:State = null)
Creates an empty machine using the provided event listeners and a given start state.
ParameterstransitionDoneHandler:Function (default = null ) — an event listener for the transitionDone event.
| |
stateEnteredHandler:Function (default = null ) — an event listener for the stateEntered event.
| |
startState:State (default = null ) — The state to use as the start state.
|
createState | () | method |
public function createState(stateEnteredHandler:Function = null):State
Creates a new state given a listener for the stateEntered event.
Parameters
stateEnteredHandler:Function (default = null )
|
State — The new State instance.
|
createTransition | () | method |
public function createTransition(source:State, target:State, eventRecognizer:Function = null, transitionDoneListener:Function = null):Transition
Creates a conditional transition between two given states using a given transitionDone listener.
Parameters
source:State — The source state.
| |
target:State — The target state.
| |
eventRecognizer:Function (default = null ) — An event recognizer that determines whether a given event triggers this transition.
| |
transitionDoneListener:Function (default = null ) — Event listener for the transitionDone event. The listener has to take a
TransitionEvent as an argument.
|
Transition — The newly created transition
|
findTransition | () | method |
public function findTransition(srcState:State, targetState:State):Transition
Finds a transistion that connects two given states.
Parameters
srcState:State — The source state to connect.
| |
targetState:State — The target state to connect.
|
Transition — A transition which connects the two states, null if no transition is found.
|
onStateChange | () | method |
protected function onStateChange(newState:State, oldState:State):void
Called when the current state changes.
Parameters
newState:State | |
oldState:State |
onTransition | () | method |
protected function onTransition(transition:Transition):void
Called when a transition is being traversed.
Parameters
transition:Transition |
performTransition | () | method |
public function performTransition(transition:Transition):void
Executes a given transition programmatically, regardless whether this is currently allowed.
This will set the current state to the transition's target state.
Parameters
transition:Transition — The transition to traverse.
|
removeState | () | method |
public function removeState(state:State):void
Removes a state from this machine.
Parameters
state:State — A state to remove. This may not be the startState
|
removeTransition | () | method |
public function removeTransition(transition:Transition):void
Removes a transition from this state machine.
Parameters
transition:Transition — The transition to remove.
|
reset | () | method |
public function reset():void
Resets this machine so that the current state is the startState
.
run | () | method |
public function run(evt:Event):void
Runs this machine using the given event source and event argument
to determine which transition to take from the currentState
.
The first enabled Transition
that will be triggered
by the given event will be traversed.
If this method is called reentrantly, the request will be queued and performed after the current
request has been finished.
Parameters
evt:Event — The event that caused this machine to run.
|
stateCreated | Event |
com.yworks.support.StateEvent
com.yworks.support.StateEvent.STATE_CREATED
An event that will be triggerd if a state has been created.
stateEntered | Event |
com.yworks.support.StateChangeEvent
com.yworks.support.StateChangeEvent.STATE_ENTERED
Dispatched when a state has been entered during a run
call.
stateExited | Event |
com.yworks.support.StateChangeEvent
com.yworks.support.StateChangeEvent.STATE_EXITED
Dispatched when a state has been exited during a run
call.
stateRemoved | Event |
com.yworks.support.StateEvent
com.yworks.support.StateEvent.STATE_REMOVED
An event that will be triggerd if a state has been removed.
transitionCreated | Event |
com.yworks.support.TransitionEvent
com.yworks.support.TransitionEvent.TRANSITION_CREATED
Dispatched when a transition has been created.
transitionDone | Event |
com.yworks.support.TransitionEvent
com.yworks.support.TransitionEvent.TRANSITION_DONE
Dispatched when the statemachine has traversed a Transition
during a run
call.
transitionRemoved | Event |
com.yworks.support.TransitionEvent
com.yworks.support.TransitionEvent.TRANSITION_REMOVED
Dispatched when a transition has been removed.