This.add.sprite has error inside functions

When I place the code directly where the function is called it works fine. I only get the error when I put it into a function