15 Replies Latest reply on Dec 3, 2007 8:21 AM by adam@blueapplestudio

    Control Panel: Rewind

    adam@blueapplestudio Level 1
      Coming from Flash I was used to testing my movie (alt+enter) to check it's performance. In Director I thought that the equivalent was pressing Rewind from the Control Panel and then pressing Play. This does not seem to be the case. The Director environment allows you to modify things on stage, and pressing rewind does not "reset" all assets. (Ex: change a texture resource on a 3D model to "textureB", stop the movie and rewind. The model still has "textureB" on it.)

      Is publishing the movie the only way to get an accurate look at how it will perform? Is there a different way I should think about the Director environment versus the Flash environment in this regard?
        • 1. Re: Control Panel: Rewind
          Level 7
          If you want to reset a 3d member, you can use this command:

          member("w3dMembername").resetWorld()

          It is not automatic like hitting the rewind button, but that is how you
          can do it. If you want, you can put it in a startMovie handler to make
          it automatically reset every time you start the movie. Be careful with
          that since some scenes will take a long time to process that command...
          • 2. Re: Control Panel: Rewind
            adam@blueapplestudio Level 1
            Thanks for the fast response. I will give that a shot.
            • 3. Re: Control Panel: Rewind
              adam@blueapplestudio Level 1
              Resetting the 3D content works wonderfully; thanks.

              Is there a similar approach to reset variables?
              Ex: In a Movie Script a global variable is declared: aDogs = ["poodle", "mutt"];
              Later in an exitFrame function I remove aDogs[1] from the array.
              When I rewind the movie and play from the start, my array aDogs doesn't reset to how it's defined in the Movie Script.

              I tried using a startMovie function both within the Movie Script and in a Behavior on frame 1 to no avail.

              Any thoughts?
              • 4. Re: Control Panel: Rewind
                Level 7
                To reset all your globals, this will do it:

                clearGlobals()

                If you just want to reset a single global, then set it to void

                gSomeVariable=void
                • 5. Re: Control Panel: Rewind
                  _eyesonly
                  One advantage of Director over many runtime environments is the ability to accurately preview the file in the authoring environment without publishing it. This allows things such as interactive debugging, not possible (AFAIK) in even Flash 9
                  • 6. Re: Control Panel: Rewind
                    adam@blueapplestudio Level 1
                    I am using clearGlobals() right before I declare the variable in my Movie Script, but am getting an error. Should I use clearGlobals in a Behavior and not in a Movie Script?
                    • 7. Re: Control Panel: Rewind
                      BSpero Level 1
                      Adam,
                      What's the error. You should probably use the clearGlobals in the startMovie script. Also, if you have sprites, etc in the first frame of your movie, and keep rewinding and starting, sometimes properties, variables, etc of those sprites don't reset properly. So, I usually don't put anything in the first frame, that way the movie forces the sprites to reinitialize when the movie starts. Is the startMovie script set properly to a Movie Script and not a behavior? Just some thoughts...

                      - B
                      • 8. Re: Control Panel: Rewind
                        adam@blueapplestudio Level 1
                        I'm defining my variable after I use clearGlobals, but it seems that my array still "has no properties". Not sure if I am using startMovie properly, but I believe I am (let me know if I'm not).

                        There are no sprites or anything else in this movie; just the below code and a Hold On Current Frame behavior on frame 4.
                        • 9. Re: Control Panel: Rewind
                          Level 7
                          Are you declaring gMyArray as a global in that script?

                          global gMyArray

                          that line should be somewhere above when you set the value of the
                          variable. If you do not declare it, then it will not save it past the
                          end of the handler.
                          • 10. Re: Control Panel: Rewind
                            Level 7
                            BSpero wrote:
                            > What's the error. You should probably use the clearGlobals in the
                            > startMovie script.

                            Be careful of that because the startMovie handler doesn't fire until after
                            the first frame has been drawn. I suspect you meant in a prepareMovie
                            script.

                            Andrew


                            • 11. Re: Control Panel: Rewind
                              adam@blueapplestudio Level 1
                              Mike:
                              I believe that my code is indeed creating gMyArray as a global. This is all using Javascript, not Lingo, so I don't think that using "global" is required.

                              Andrew:
                              I tried prepareMovie instead of startMovie and get the same error. Does prepareMovie execute similar to startMovie?

                              I am unclear as to why if I 1) clear globals and then 2) create a global variable that the variable can come up later as having no properties. It would make sense to me if I created the variable and THEN cleared globals. Any thoughts?
                              • 12. Re: Control Panel: Rewind
                                Level 7
                                adam@blueapplestudio wrote:
                                > Mike:
                                > I believe that my code is indeed creating gMyArray as a global. This
                                > is all using Javascript, not Lingo, so I don't think that using
                                > "global" is required.
                                >
                                > Andrew:
                                > I tried prepareMovie instead of startMovie and get the same error.
                                > Does prepareMovie execute similar to startMovie?
                                >
                                > I am unclear as to why if I 1) clear globals and then 2) create a
                                > global variable that the variable can come up later as having no
                                > properties. It would make sense to me if I created the variable and
                                > THEN cleared globals. Any thoughts?

                                You /are/ declaring the global at the top of every script that needs to
                                access it, aren't you?

                                --------------------------------------
                                global myGlobal

                                on myHandler
                                myGlobal=myGlobal+1
                                etc.
                                --------------------------------------

                                Andrew


                                • 13. Re: Control Panel: Rewind
                                  adam@blueapplestudio Level 1
                                  Andrew,
                                  I'm not doing that as I thought it wasn't necessary with JavaScript, only Lingo. What is the syntax for that in Java? You seem to be able to access the variable from other Behavior scripts without it just fine (See the attached code example).
                                  • 14. Control Panel: Rewind
                                    BSpero Level 1
                                    Andrew,
                                    You're right. Do it on the prepareMovie.

                                    Adam,
                                    Take a look at the Director docs regarding global variables in JavaScript syntax. It says they are considered global by default, but in order to use them in other scripts, you have to declare them with _global. Here's an excerpt;

                                    Global variables in JavaScript syntax
                                    In JavaScript syntax, variables are considered global by default. The scope of a global variable can be determined by how and where it is declared.

                                    If you declare a variable within a JavaScript syntax function without preceding the variable name with the keyword var, the variable is available to all functions within its containing script.
                                    If you declare a variable outside a JavaScript syntax function, with or without the keyword var, the variable is available to all functions within its containing script.
                                    If you declare a variable inside or outside a JavaScript syntax function by using the syntax _global.varName, the variable is available to all scripts within a movie.
                                    The following example uses the syntax _global.gMovie in one script to declare the variable gMovie as global. This variable is available to all scripts within the movie.

                                    // JavaScript syntax
                                    _global.gMovie = 1; // Declare gMovie in one script

                                    // Create a function in a separate script that operates on gMovie
                                    function mouseDown() {
                                    _global.gMovie++;
                                    return(_global.gMovie);
                                    }
                                    The following example declares the global variable gScript in one script. This variable is available only to functions within that script.

                                    // JavaScript syntax
                                    var gScript = 1; // Declare gScript in a script

                                    // gScript is available only to functions in the script that defines it
                                    function mouseDown() {
                                    gScript++;
                                    return(gScript);
                                    }
                                    In JavaScript syntax, when you define variables before any handlers, the variables automatically have undefined as their initial value.
                                    • 15. Re: Control Panel: Rewind
                                      adam@blueapplestudio Level 1
                                      Andrew, BSpero, Mike, and _eyesonly:

                                      Thanks for all of your help. I am using prepareMovie now, but my main problem was the variable declaration. I didn't realize that there were different shades of "global" when it comes to a global variable's scope. Using the syntax _global.gMyArray = ["A", "B", "C"]; is delivering the result I was looking for.

                                      The online Director docs are now bookmarked and will be my first stop for assistance now.

                                      Thanks again everyone.