The following code (attach) works in nb, but doent work in the cdf preview. Why? Is it the MessageDialog?
Your original example depends on a user evaluating the code in the notebook, which they cannot do in CDF Player. So to remove this requirement, you would need/want to use DynamicModule. And note the use of SaveDefinitions in the attached.
http://reference.wolfram.com/language/ref/DynamicModule.html
Ian