2 Replies Latest reply on Apr 16, 2008 12:15 PM by adam@blueapplestudio

    What Should I Use stopMovie For?

    adam@blueapplestudio Level 1
      Recently I have discovered that I need to remove all instances of the keyframePlayer modifier in a stopMovie function, or else when my projector is closed an error message appears.

      An on stopMovie handler is a good place to put Lingo that performs cleanup tasks--such as closing resource files, clearing global variables, erasing fields, and disposing of objects--when the movie is finished.

      I come from a Flash background, and am just now starting to learn about how memory is handled. Do I need to delete objects and clear variables in the stopMovie function as well? Is there a rule of thumb to follow? I am not getting an error when I close the projector now… am I safe?
        • 1. Re: What Should I Use stopMovie For?
          Chunick Level 3
          you can use either:
          clearGlobals()
          or
          _global.clearGlobals()
          or for Javascript only (undocumented)
          _system.gc()

          depending on the version of Director. That will clear all global variables. Other than that, you should kill all objects such as script created members, Xtras and timeOut objects.

          to kill an individual global variable:
          global gSomeVar
          ..
          ...
          gSomeVar = VOID

          ie.
          mem = new(#bitmap)
          or mem = _movie.newMember(#bitmap)
          ..
          ...
          mem.erase()

          fileObj = xtra("FileIO").new()
          or fileObj = new(xtra "FileIO")
          ..
          ...
          fileObj = 0

          timeOut("timeout object").new(1000, #someTimeoutHandler, me)
          or timeOut().new("timeout object", 1000, #someTimeoutHandler, me)
          ..
          ...
          timeOut("timeout object").forget()

          all these objects can be killed where they were created locally and unless you're using global variables, don't need to be killed in the on stopMovie handler... the clearGlobals() is a catchall that will do the trick.

          further reading:
          clearAsObjects()
          clearCache
          unload()
          unloadMember()
          unloadMovie()
          • 2. Re: What Should I Use stopMovie For?
            adam@blueapplestudio Level 1
            Thanks for your response; this is exactly what I was looking for.