There's nothing wrong with the code. It's inside a package. That means it goes in its own actionscript file, which you then import when you want to use it. You're supposed to change package {} to package folder.folder2.whatever {} depending on the relationship of the actionscript file to your actual FLA. You can't copy and paste this into the Actions panel.

For more information...
http://bit.ly/wwPwcj