# Defining functions in a CDF and Manipulate [closed]

I want to deploy an interactive CDF that may depend on several functions. How do I define those functions? I'm using Manipulate, I defined the function inside it prior to returning the value I want, that is

CDFDeploy["test01",
Manipulate[
f = Function[x, x^2];
f[z],
{z, 0, 10}]]


This indeed yields what I want

I have, however, a few questions:

• Is there a better way of defining functions to be used within a CDF? I wonder if it can be more efficient. For example, defining f before Manipulate doesn't work.
• When I try to use, for example, f[x_] := x^2, the notebook starts to blink and freezes. Any idea why?
• I've been mostly using Manipulate, but I've also heard of DynamicModule for interactive CDFs. I'm not very acquainted with it. Could it be useful in my case?
• Define inside using Initialization or outside using SaveDefinitions. – Kuba Jan 14 at 15:32
• Great! I've added an answer for the record, based on your comment. Thank you. – sam wolfe Jan 15 at 22:26

## 1 Answer

Following the comment by Kuba ♦ in the comment section, using Initialization solves my problem

CDFDeploy["test01",
Manipulate[
f[z],
{z, 0, 10},
Initialization :> (f[x_] := x^2)]]