# \[ASK\] Implementing FSM with Actionscript 2.0

**URL:** <https://forum.kirupa.com/t/ask-implementing-fsm-with-actionscript-2-0/328946>\
**Category:** programming\
**Created:** [July 5, 2012, 1:59pm UTC](https://forum.kirupa.com/t/ask-implementing-fsm-with-actionscript-2-0/328946 "2012-07-05T13:59:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noth1ng](https://avatars.discourse-cdn.com/v4/letter/n/f475e1/32.png) [@Noth1ng](https://forum.kirupa.com/u/Noth1ng)\
**Post date:** [July 5, 2012, 1:59pm UTC](https://forum.kirupa.com/t/ask-implementing-fsm-with-actionscript-2-0/328946/1 "2012-07-05T13:59:23Z")

</div>

hi there ,

i have seen many of references of AI and FSM like :  
[http://www.richardlord.net/blog/finite-state-machines-for-ai-in-actionscript](http://www.richardlord.net/blog/finite-state-machines-for-ai-in-actionscript)

> **[State Machines By Example: A Useful FSM](http://magicscrollsofcode.blogspot.com/2012/02/state-machines-by-example-useful-fsm.html)**
>
> Introduction A finite state machine is a highly useful tool for programmers in general and for video game programmers in particular. If you...

and sadly im still can’t understand the point of the FSM on AS2.0  
is it a must to create a class of each state ?

i have a project of game and also it has an AI,  
the AI has 3 state n i said the state is distanceCheck, ChaseTarget, and Hit the target,

the game that i create is FPS game and play via by mouse

so what i mean is i have create an AI ( and is success ) but i want to convert it to FSM method …

i create :  
function of CheckDistanceState() and in that function i have to locked the target with an array, and sort it with the nearest distance and locked it and it trigger the function ChaseState(), and in the ChaseState() i insert the Hit() function to destroy the enemy,

the 3 function that i created , i call it in the AI\_cursor.onEnterframe, ( FPS game that only have a cursor in stage )

is there any chance to implement FSM to my code without to create a class ??  
from what i read before , to create a class mean to create an external code outside of the frame ( i used to code in frame) and i stil dont about it.

sorry if my explaination not clear …
