Thanks, I had the same problem and this solved it.
TL;DR wrap the script code for PlayerAnimationSprite in a function called: function PlayerAnimationSprite( ) { .... }