5 Replies Latest reply on May 25, 2006 4:18 AM by esset09

    View not updateable until all code has executed

    esset09
      I have problems updating the view (i.e. tracing debug texts, displaying load clips) when larger code blocks are executed in Flash.

      Here's an example:

      The following code is executed when releasing a dragged MovieClip (starting drag with onMouseDown and moved by following mouse position onMouseMove):

      ...

      var classRef:SettingsHandler = this;

      duplicateMc.onMouseUp = function() {
      trace("Releasing object...");
      classRef.releaseDraggedPlayer(this);
      }

      ...

      The method "releaseDraggedPlayer(movieClip:MovieClip):Void" executes a number of other methods in a larger chain and the execution takes a little while to complete (about 1500 ms).
      What I want to do is to display a "loading" message while the "releaseDraggedPlayer()" method is executed. The problem is that Flash doesn't allow me to update any graphics (or even use "trace()") until the entire code block has been executed. Once the execution has finished, all "trace()" messages (and any other graphical changes I've done during the execution) are displayed.
      In this particular case, the trace ("Releasing object...") is displayed in the output once the last line of code in "releaseDraggedPlayer()" has been executed.

      I have also traced the timestamps of when the lines are executed, and they're executed in the correct order and with correct intervals so it's all about when it's displayed in the output...

      Notes:

      - I'm exporting in Flash 7
      - The application is of medium size (?) - about 30 classes (mainly data objects, though) and a 1 MB ".fla"
      - I have tried to separate the execution so that it's done in smaller "steps" (i.e. by using Delegates), but that doesn't help
      - I've tried to move the execution into a MovieCilp (as onEnterFrame()), but that didn't work either


      Is this something in Flash/ActionScript that's impossible to get around? Does anyone have a fantastic solution to this problem?

      Please help me out here!
        • 1. Re: View not updateable until all code has executed
          Deepak Joshi
          onMouseUp; display the loading message.
          Only after the message is displayed; the entire chain of your functions will start executing.
          Once the functions have been executed; unload the loading message.
          • 2. Re: View not updateable until all code has executed
            esset09 Level 1
            But wouldn't that be the same thing as I'm doing now? The trace "Releasing object..." isn't displayed until all code has been executed as it is now, so displaying the message before that shouldn't work either (?)...

            I guess you mean that I should write the following (?):

            ...

            var classRef:SettingsHandler = this;

            duplicateMc.onMouseUp = function() {
            classRef.displayMessage();

            classRef.releaseDraggedPlayer(this);
            }
            • 3. Re: View not updateable until all code has executed
              blemmo Level 1
              Have you tried updateAfterEvent()? Not sure if it will work for the trace, but maybe it works for the "loading" display:
              duplicateMc.onMouseUp = function() {
              classRef.displayMessage();
              updateAfterEvent();
              classRef.releaseDraggedPlayer(this);
              }

              I never experienced this kind of problem, but I see updateAfterEvent() used sometimes, so maybe it may help here.

              cheers,
              blemmo
              • 4. Re: View not updateable until all code has executed
                esset09 Level 1
                Yes, I'm afraid I've already tried updateAfterEvent() without success...
                • 5. Re: View not updateable until all code has executed
                  esset09 Level 1
                  I found the solution to this issue, with help from "Aneesh" at experts-exchange:

                  "Hi,

                  Only solution to this problem is divide the executing code into multiple frames, actually flash compiles complete code of a frame at once,
                  If code takes time then it will not paint anything inbetween.
                  dividing code can be achieved using onEnterFrame, the main trick here is in converting a single frame code in onEnterFrame code...

                  If you can provide upload source code for reviewing I might do it for you.

                  Rgds
                  Aneesh"

                  So I divided my code, so that my "loading" message is called from within an onEnterFrame method, and at the end of that I create a new MovieClip with an onEnterFrame method that invokes the major "releaseDraggedPlayer()" method.