4 Replies Latest reply on Jul 7, 2006 3:53 PM by Rothrock

    Two simultaneous calls to this.onEnterFrame dont work

    spinz2112
      My code is supposed to drag an mc around the stage, and then copy its coords to an array, and then be able to replay it. I use a function to 'play' the coordinates back, but for some reason, if i divide up the start and end frames (which are actually the indices of the array holding the x and y coords), the this.onEnterFrame only enters the last time around.

      you will need an mc called 'mc1' on the stage, and another mc called 'playButtonMC' which is going to be the play button.


      the problem can be manipulated using this function

      function replayTest():Void{
      playMovieClip(mc1,0, 10);
      playMovieClip(mc1, 10, 20);
      }

      it seems with 2 calls to playMovieClip, the first drag never works, and the replay actually begins from the beginnig of the second playMovieClip call. with one call however, works just fine. try running this with only the first playMovieClip (comment the second one), and then try uncommenting the second and rerunning.
      Can someone tell me how to get both 'playMovieClips' to work chronologically please?

        • 1. Re: Two simultaneous calls to this.onEnterFrame dont work
          spinz2112 Level 1
          just to add a quick note, in the playMovieClip function, I added a "trace(clip.onEnterFrame)" and the trace was outputting 'undefined' the first time around, but '[type function]' the second time around.

          hopefully this kind of narrows down the problem, any suggestions on how to fix it? thanks
          • 2. Re: Two simultaneous calls to this.onEnterFrame dont work
            Level 7
            > this.onEnterFrame only enters the last time around.

            That's as it should be. You are first creating an enterFrame handler, then
            *replacing* it. A clip can only have one enterFrame handler.

            Difficult to say what you can do to overcome this without a bit more detail.
            Why can't you just use:

            function replayTest():Void {
            playMovieClip(mc1, 0, 20);
            }

            for instance? An alternative would be to assign a callback function or
            listener, but need more detail about what you are trying to accomplish.

            > just to add a quick note, in the playMovieClip function, I added a
            > "trace(clip.onEnterFrame)" and the trace was outputting 'undefined' the
            first
            > time around, but '[type function]' the second time around.

            I can't replicate that behaviour at all...
            --
            -------------------------------
            Remove '_spamkiller_' to mail
            -------------------------------


            • 3. Re: Two simultaneous calls to this.onEnterFrame dont work
              spinz2112 Level 1
              the reason i have multiple calls to the play function is because in the example above, i only have one mc that gets dragged, but in my real life experiment, there are many mc's and each needs to get play sequentially. with my above problem, only the last play call functions.

              does anyone know of any workaround to solve this?

              also, by the trace(clip.onEnterFrame) output, all you need to do is replace trace(typeof(clip)) in the playmovieclip function, that will output the undefineds and the type functions.

              so im still looking for away to use the multiple playmovieclip funciton, any suggestions would be appreciated!
              thanks
              • 4. Re: Two simultaneous calls to this.onEnterFrame dont work
                Rothrock Level 5
                Well if you want things to play sequentially you will have to have something that says "Hello, I'm done. Next thing you now may start."

                So when you call your replay have it replay all (or whatever set you want) of the recorded positions for mc1. Then when that completes have the onEnterframe call the function for mc2. And so on. Without know all that you are doing it is hard to say exactly how best to go about it.

                But as Peter said you can only have one onEnterFrame defined for a give instance at a time. Of course if in your example you had mc1 and mc2, like so:

                playMovieClip(mc1, 0, 10);
                playMovieClip(mc2, 0, 10);

                They would both work, but they would go at the same time – not sequentially. All the code in a given frame is executed and then the screen updates. So both calls to playMovieClip would be made before the frame left.