What am I doing wrong with this function?

you may have more chance of a solution if you upload the fla