10 Replies Latest reply on Jul 13, 2006 9:02 AM by spinz2112

    Dragging and playing back multiple MC motion

    spinz2112 Level 1
      Ive been on this case for a while now, and really havent gone anywhere with it.

      Just curious to see if anyone has any samples or examples of multiple MC's being dragged around, their motion recorded and then played back.

      I dont seem to be having trouble with moving one mc around and playing it back. i store the coords of the mc (onenterframe) into an array, and on playback just traverse back the array.

      Im having difficulty when there are more than one mc's, trying to figure out which mc's moved in which order, and what not.

      I dont want to store all the mc's coords in one array, but have their own array. The reason for this is, that the second part of my problem is figuring out a way of assigning multiple mc's to move simultaneously.

      i guess the easiest way to think of this would be like drawing a foot ball play on the computer and replaying it back. Anyone have suggestions?
      Thanks
        • 1. Re: Dragging and playing back multiple MC motion
          JakeTheSnake3.0
          Make a global timer. When an mc starts moving, record what time it started playing in reference to the global timer. Then, when you want to play back the recording, just do a setInterval to that variable.
          • 2. Re: Dragging and playing back multiple MC motion
            Rothrock Level 5
            This is really kind of a complex project and it seems that there is a lot to the design of it. There are probably at least a dozen good ways to do this. But the main guidance I would give you is, "If you need to keep track of something – then do so!" In otherwords, if each clip having one array isn't letting you keep track of which order things were moved in, then start a new array that just keeps track of that.

            So there are two modes – playback and record. The needs of playback will dictate what is recorded in record mode. So let's think about playback mode first.

            Playback also has two modes – simultaneous and sequential. Sometimes the clips will need to play in the order they were originally moved and sometimes two or more will need to do their thing at the same time. Is this right so far?

            If that is the case then I would probably us a lot of arrays. We need to track any give move of an item as well as the over all order of their movements.

            So each time a clip is moved I would create an array, they could be numbered sequentially or with a time stamp of some sort so that if clip5 was moved and then a bit later it was moved again it would have two arrays recording the two different paths. I would probably call these pathArrays and store them within the clip themselves. So clip5.pathArray1, clip5.pathArray2, and so on.

            At the same time, I would have another array that records the order or movement. So the first time clip5 moved it would also record that clip5 moved first. Does that make sense? I would probably call this the moveOrder array and there would be one for the whole setup. It would probably contain info like this:

            moveOrder[0]={name:clip5,seq:0,startTime:1387}

            That would read that the first thing moved was clip five, it is the first time (remember arrays are zero based) that particular clip has been moved, and it was first dragged 1387 milliseconds after the player started. You might also add other bits of info that you need to record. The next time clip 5 is moved its seq number will be 1, then 2, and so on.

            Playback would then step through the moveOrder array, reference it to figure which pathArray to replay, when the playback got to the end of the pathArray it would check the next element in the moveOrder array to see what to play.

            If you know that just want to see all the paths of a given clip you would just iterate through all of the pathArrays or if you wanted all the odd number clips to move at the same time you would just iterate through all their pathArrays.

            Anyways, what do you think? Would that meet your needs?
            • 3. Re: Dragging and playing back multiple MC motion
              spinz2112 Level 1
              the global time idea just wont work for this situation because there is a situation where i would have to record a couple of different mc's and then replay them simultaneously.

              here is what i was thinking, to solve that problem. In my mind I had an idea of having a SEQUENCE array and each MC having an array of coords. So ideally here is what should happen.
              Start with sequence 1, sequence array is going to have a sequence number, mc name, frame start and frame end fields.
              in sequence 1, we move mc1, the coords for this motion are gonna be stored in the mc1 movement array between index 0 and say 10.
              and in the subsequent motion (we will increment the sequence counter), we basically have the same thing for mc2.

              i figured that if two mc's have the same sequence number, then they should be categorized as moving together. realistically, we are dragging the first mc, and not incrementing the sequence counter, and then dragging the second mc. problem solved...easy right? haha..well, my problem is actually in the playback.

              here is some code for the playback problem, i havent dived into the sequence counter problem yet.

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


              the problem i am having is with the replayTest function and the playMovieClip function.

              supposedly you can only have one, onEnterFrame, so im having trouble figuring out how to playback the multiple stored motions.

              for this example I have
              playMovieClip(mc1,0, 10);
              playMovieClip(mc1, 10, 20);

              then only reason that i have broken the framestart and end up is because i want to show the problem of playing multiple mc's without having a ton of code. realistically the clip name arguments are gonna have the different mc clip instance names.


              if anyone can help me rewrite this play function, that would be awesome.
              thanks
              • 4. Re: Dragging and playing back multiple MC motion
                spinz2112 Level 1
                Rothrock, you were replying just while i was too. We were both kind of thinking of the same thing.

                Im just having difficulty coding the above, maybe you can help me out with the play function above that i am really having difficulty figuring out.
                thanks!
                • 5. Re: Dragging and playing back multiple MC motion
                  Rothrock Level 5
                  You are wrong about the only having one onEnterFrame. Each instance can only have one onEnterFrame handler defined at a time, but every instance can have its own at the same time.

                  The problem is:

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

                  Even if the playMovieClip function could do two onEnterFrames for the same clip (in this case mc1) there is nothing to say, do this first and then do this next. If it was two different clips then they should both playback just fine.

                  You say " i want to show the problem of playing multiple mc's without having a ton of code" but I think it is going to take a lot more code to make this work.

                  You need to add something into the playback function that says, "okay I've been told to playback MC1s pathArray from steps 0 to 10, now that I'm at step 10 I will delete my current onEnterFrame, and get the next thing I am supposed to play and do another round of playback.

                  I really think the many different arrays approach is going to clear up a lot of things for you. I don't think your current approach to the record keeping aspect of this project will lead to success. If the records are in order then the play function will almost take care of itself!

                  Muck with that a bit and post back. We can take it from there.
                  • 6. Re: Dragging and playing back multiple MC motion
                    spinz2112 Level 1
                    quote:

                    Originally posted by: Rothrock
                    You need to add something into the playback function that says, "okay I've been told to playback MC1s pathArray from steps 0 to 10, now that I'm at step 10 I will delete my current onEnterFrame, and get the next thing I am supposed to play and do another round of playback.

                    I really think the many different arrays approach is going to clear up a lot of things for you. I don't think your current approach to the record keeping aspect of this project will lead to success.


                    ok, so i did a quick simple test, to the code I have here, i attached another mc, called it mc2, created a movement array and added the onpress and onrelease just like the mc1 has.

                    seems that with two mc's and two playmovieclip calls with different 'clip' names, the playmovieclip function just plays them together. Light bulb! this would take care of my simultaneous motion problem.

                    but im still wondering how i can play (mc1, 0, 10) and then play from 10-20 with succesive calls.

                    ive tried many different versions of delete.onenterFrames, but nothing has worked. Can you tell me how to do this?

                    I agreee completely with you on having another array that stores the sequences, and that is what I tried to explain in my earlier post, maybe you didnt understand. the sequence array is going to store the sequence number, mc name, frame start and frame end. im going to have another button on stage called next sequence or whatever, and its going to be a counter.

                    each sequence counter tellls me what order to process the motions, in one sequence counter, if there are more than one mc's then i play them simultaneously.

                    before i get there, im having difficulty with the simplest play back problem with the playMovieClip function. If i can get some help on how I can modify it so that each playMovieClip funciton call will be independent of each other, thereby making it chronological, that would be awesome.
                    thanks!
                    • 7. Re: Dragging and playing back multiple MC motion
                      Rothrock Level 5
                      So to get it started you would do this:

                      playMovieClip(mc1,0, 10);

                      Then inside your playMovieClip conditional you would add something like:

                      if(frStart==frEnd){
                      delete clip.onEnterFrame;
                      playMovieClip(mc1,10,20);
                      }

                      That is the easiest way to hard code it. But of course you would just add another function perhaps to check in your sequencing array to see if there was another step and have that call playMovieClip if it found it needed to play the next one from the array. Does that make sense?

                      Just one thing I don't think keeping everything for each clip in one array and then called records 1057538 to 1123109 is a good approach. It is possible that your array will get really big and slow things down a bit. I don't have any certain knowledge on this, but it just seems that many smaller (yet still possibly quite large) arrays will be easier to manage. Maybe I'm wrong, maybe I'm not!
                      • 8. Re: Dragging and playing back multiple MC motion
                        spinz2112 Level 1
                        rothrock,
                        so just that small change of adding the second playmovieclip nested inside the playmovieclip function did produce movement of one mc after the other, but the coding gets really ugly. is there any way that i can delete the onEnterFrame from inside the playmovieclip function, then go back to my replayTest function and then call the second playMovieClip function?

                        The reason I ask this is because the replayTest function is going to have all the code for processing the sequence array and figuring out what mc's need to be played in what order and such. I couldnt possibly do this if the subsequent calls to playMovieClip were nested inside the playMovieClip function.

                        does that make sense? thanks
                        • 9. Re: Dragging and playing back multiple MC motion
                          Rothrock Level 5
                          The answer is, I don't think so. I'm not really sure what you mean by all that. Lets say I want to move the following clips:

                          mc5, 20, 50
                          mc2, 1058, 1192
                          mc5, 51, 800

                          I would store that in an array and just have my function move mc5 through its steps, then have the function check the array and see the next element is for mc2 and have it start moving that, and so on until the sequencing array was empty. Functions are free (well nearly so) so just create a new function that checks if you are done with your sequence or not and place that inside your conditional.
                          • 10. Re: Dragging and playing back multiple MC motion
                            spinz2112 Level 1
                            ok..we are on the same page. we are both thinking of the same thing, and i understand what you telling me to do.

                            the code to run through the sequence is going to be in the replayTest function. I want to be able to call the playMovieClip funciton, which basically says i want to play this movieclip from frame-n to frame-m, from the replayTest function and then we can all be in happy land.

                            just for my test case i had two calls to mc1, divided up into frames 0-10 and frames 10-20. (the numbers are actaully the indices on the movement array).

                            this is where the code boinks...it does only the last call to mc1..and not the first one. i am trying to figure out how to call the playMovieClip function from within the replayTest function without having to recursively call it from within the playMovieClip function.

                            the best way to see what i am talking about would be to put the code into and fla and try it out. hopefully this clears out some air.