How to use the onStateChangedEvent from AnimatedSprite?

I'm not sure how to use the onStateChangedEvent from AnimatedSprite, I want to use it to run code when changing to certain states, that way you can just use the self:switchStates("stateName") whenever you want to switch states, while still having the appropriate code for that event being run. that said, if their is an easier way of getting code to run on switching to a specific function, please say, this is my first time using AnimatedSprite, so I'm just learning as I go :sweat_smile: