The current Greenfoot version is 2.1.2, so that might be your problem. I copy/pasted your code into a test Actor, added the relevant variable, and it worked perfectly for me.
Okay, thanks Builder. I did reinstall Greenfoot anyway and everything seems to be working now. I updated to Lion since I used Greenfoot last, so maybe there was a glitch when I upgraded, who knows? Seems to be operating find now. Sorry for the trouble.