I wrote a function and saved it in a package. I saved a copy of the package in the Autoload folder too. I deployed a CDF that contains this function. When I open the CDF later, this function (which represents modified input fields) is not evaluated. But when I do any operation that evaluates this function (like a button click), it gets evaluated and the cdf works just fine.

I am using Mathematica 9 to deploy the cdf and also to run it to check it.

Updated, the package's code down below -

BeginPackage["ModifiedInputFields`"] InputFieldsCreation[noOfrows_, 
 noOfInputFields_] :=

    {inputvaluelist = Table[0, {noOfrows}, {noOfInputFields}]},
        (noOfrows > 0),
        (*If noOfrows value is greater than 0*)

                            With[{i = i, j = j}, (Row[{

                                                Dynamic[inputvaluelist[[i, j]]],
                                                ContinuousAction -> True,
                                                ImageSize -> {50, 20},
                                                Alignment -> Center

                            (*with is closed*)
                            {i, 1, noOfrows},
                            {j, 1, Length[Part[inputvaluelist, i]]}
                    ],(*Table closed*)

(*Module closed*)

What I am looking at is to also be able to extract all the inputs that the user gives in the input fields into a list that we pass on to other functions. So that is a critical feature, which I am worried might also be a reason for the package giving trouble at cdf startup.

  • $\begingroup$ @Nasser the person I am intending to send this cdf has mathematica installed, and I am planning on sending the packages to them too. They will also be running the cdf from mathematica 9. I see this problem when I try to open this cdf from another computer as well as when I re-open mathematica. Any button press that has the function evaluation as an action makes the function work, but not when the cdf is just started. I get big red boxes across all the modified input fields i created. $\endgroup$
    – Murali
    Commented Jan 26, 2013 at 11:33
  • $\begingroup$ We've done this before, writing packages and then using Needs to call them and then the deployed cdf working just fine. We use Dynamic Module regularly instead of Manipulate, never used SaveDefinitions option though, I don't think it is available for Dynamic Module. $\endgroup$
    – Murali
    Commented Jan 26, 2013 at 12:01
  • $\begingroup$ Very hard to comment and help without code or screen grabs of the problem. $\endgroup$ Commented Jan 26, 2013 at 21:25
  • $\begingroup$ @MikeHoneychurch I am editing the question and adding the code, all of my package $\endgroup$
    – Murali
    Commented Jan 27, 2013 at 7:44

2 Answers 2


If you use Enterprise Mathematica edition, or some kind of signed version, you can do what you want. In this example I use the CDF with package to hide a database connection, so the package can be distributed without someone discover your connection user name and password.

There is the package, that should be saved together with the CDF file (same directory):


marcheConn::usage="myConn[] connect to database";


myConn[] := 
        JDBC["Microsoft SQL Server(jTDS)", "myIPAddress"], 
        "Username" -> "userName", 
        "Password" -> "password"


Here is the code for the test CDF


            Button["Random Sample from Database",output=test[]],
            Button["Current directory",output=Directory[]],

            r=SQLExecute[conn,"select * from someTable"];

Now you can export this using:

CDFDeploy["test.cdf", testCDF, "Method" -> "Standalone", "Target" -> "PlayerPro"]

Important points:

  • When using Needs inside Initialization use the full package directory in the second argument.
  • When using the functions from your package inside Initialization you should use it full name as connectionPack`myConn[]
  • Just for completeness of this example. If you wand to protect you connection string you could Encode and use SetAttributes[myConn, {ReadProtected,Locked}];. This way user can not retrive it using ??myConn.


I discovered that the encryption do not solve the conn security. When you create the connection, you can retrieve all connections parameters just executing conn. The only advantage is that the user needs Mathematica to do this, and user and pass will not be in plain text.

  • $\begingroup$ I have edited my question with my code. In your code, I want to see it work when the first button, whose action is output=test[] to not be there, instead that action should happen automatically when the cdf opens. $\endgroup$
    – Murali
    Commented Jan 27, 2013 at 8:05
  • $\begingroup$ Have you tried to put it in Initialization?? Witch version is your CDF? Signed or not? $\endgroup$
    – Murta
    Commented Jan 27, 2013 at 12:53
  • $\begingroup$ Yes, tried initialization, I think the cdf is unsigned. We are developing and evaluating internally using Mathematica 9 standard license. $\endgroup$
    – Murali
    Commented Jan 27, 2013 at 13:52
  • $\begingroup$ I understand. I think that to do what you want you need a signed version. To make the code of my post work I used the Enterprise Version. $\endgroup$
    – Murta
    Commented Jan 27, 2013 at 14:00
  • $\begingroup$ Did you actually test the use of ReadProtected? I seem to remember that this attribute was not allowed -- but may be wrong. $\endgroup$ Commented Jan 27, 2013 at 21:29

From the docs: "Because CDF Player cannot load custom data at runtime, you must ensure that all necessary information is embedded within the interactive elements of your .cdf file. This can be done with either Initialization or SaveDefinitions; both are options to Manipulate."

  • $\begingroup$ the cdf is being tested in mathematica itself. Meant to be tested for proper running in Mathematica, before we finally aim to push it for use in player pro, but that is in the future. It should have worked when opened in Mathematica. I've seen this thread -> Understanding CDF But discussion centers around cdfs for cdf players and player pro's $\endgroup$
    – Murali
    Commented Jan 26, 2013 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.