10 Replies Latest reply on Jun 15, 2010 9:44 PM by kglad

    pausing a function

    Shad0wdrag0n

      I have a hitTest function that keeps checking if two objects contact each other. I'm currently using the following code:

       

      function checkOverlap():Void {

           if(doorHit.hitTest(player)){

                attachMovie("message1", "message1", this.getNextHighestDepth(), {_x:340, _y:280});

           }

           else{

           message1.removeMovieClip();

           }

      }

      var nOverlapInterval:Number = setInterval(checkOverlap, 100)

       

      The message1 MC has a bunch of links that do stuff within the message1 MC, but because the interval keeps running it keeps resetting the message1 MC. Is there any way to pause the interval for as long as the player MC is in contact with the doorHit MC then unpause it when the two MCs are no longer touching? I've thought about making it so that message1 is already on the stage but outside the viewable area. The hitTest function would then move the message1 MC back and forth. But, I want to figure this out so I can also pause functions when the movie moves to a different frame then unpauses when it comes back to the frame with the hitTest. So, is there a way to make this work?

        • 1. Re: pausing a function
          kglad Adobe Community Professional & MVP

          you don't want to pause (or clear) your interval.  use:

           

          function checkOverlap():Void {

               if(doorHit.hitTest(player) && !alreadyTriggeredBool){

          alreadyTriggeredBool=true;

                    attachMovie("message1", "message1", this.getNextHighestDepth(), {_x:340, _y:280});

               }

               else{

          alreadyTriggeredBool=false;

               message1.removeMovieClip();

               }

          }

          var nOverlapInterval:Number = setInterval(checkOverlap, 100)

           

           

          • 2. Re: pausing a function
            Shad0wdrag0n Level 1

            That doesn't seem to be working. When the player MC moves into contact with the doorHit MC it just keeps adding and removing the message1 MC over and over every second or so.

            • 3. Re: pausing a function
              kglad Adobe Community Professional & MVP

              is player moving out of contact with the door every second or so after door contact and then back into contact?

              • 4. Re: pausing a function
                Shad0wdrag0n Level 1

                Nope, the player MC completely overlaps the doorHit MC, so they never break contact.

                • 5. Re: pausing a function
                  kglad Adobe Community Professional & MVP

                  then you didn't accurately copy the code i suggested.  retry.

                   

                  if you think you copied it correctly, copy and paste the relevant part of your code.

                  • 6. Re: pausing a function
                    Shad0wdrag0n Level 1

                    I copied the code directly out of the post, so the code from my document is exactly the same as the code from your post. All of the MCs are out in the open so they can be fully overlapped, they don't just touch by the edge or anything, and they don't move when in contact. The code works fine, except that it keeps doing both the if and the else parts over and over. Does it have something to do with the inverval? Would that keep resetting the true/false variable?

                    • 7. Re: pausing a function
                      Shad0wdrag0n Level 1

                      I also seem to be having problems with an onKeyUp listener I added to the movement code for the player MC. Something is causing code to act in ways it's not supposed to and I can't figure out what's doing it. Is there a place I can upload my .fla file to have someone troubleshoot it? I can get these codes to work when they're on their own in separate files, but as soon as I put them together into my main .fla file they stop working properly.

                      • 8. Re: pausing a function
                        kglad Adobe Community Professional & MVP

                        use:

                         


                         

                        function checkOverlap():Void {

                             if(doorHit.hitTest(player) ){

                        if(!alreadyTriggeredBool){

                        alreadyTriggeredBool=true;

                                  attachMovie("message1", "message1", this.getNextHighestDepth(), {_x:340, _y:280});

                        }

                             }

                             else{

                        alreadyTriggeredBool=false;

                             message1.removeMovieClip();

                             }

                        }

                        var nOverlapInterval:Number = setInterval(checkOverlap, 100)

                         

                         

                        • 9. Re: pausing a function
                          Shad0wdrag0n Level 1

                          That's got it. Separating the hitTest and alreadyTriggeredBool into two if statements seems to have fixed the problem.

                          • 10. Re: pausing a function
                            kglad Adobe Community Professional & MVP

                            yes, my previous suggestion was problematic with both conditions in the same if-statement..