6 Replies Latest reply on Oct 27, 2009 11:26 PM by kglad

    else delete interfering with other MCs?

    shintashi Level 1

      I've been working on this for a while now, making a language learning game where if the "man" comes in contact with a particular tile object, a screen pops up prompting question or dialog about that object. (for example, if you ran into a red jar, it might ask you what color it was, in Japanese). I thought everything was working fine until I tried the function with a second tile. Now the textbox "blips" - it loads for only 1 frame then disappears, probably because the existence of the other function is telling it to delete, because "man" isn't in both places at the same time.

       

       

       

       

      ----

               function zone(mc, zquestion, one, two){
              if(man._y < mc._y +50 && man._y > mc._y -50 && man._x < mc._x +100 && man._x > mc._x +25){
              var glowInstance2:GlowFilter = new GlowFilter(0x22FF22, 0.6, 8, 8, 4);
          mc.filters = [glowInstance2]; //makes kanji signs and so forth light up.
                 
                  mc.onRelease = function(){
                      textscreen(zquestion, one, two);
                  }
              }else {delete mc.onRelease; mc.filters = null; killscreen();}
         
          }
        
      onEnterFrame = function(){
          zone(pallete2.sign81, "Can you read this?", "Yes", "No");
      zone(pallete.planks63, "How about this?", "Yes", "No");

      }

       

      ----

       

      is there a way to correct this problem?

       

      P.S. I can post the codes for textscreen() and killscreen() if necessary - they are functions for drawing a textbox and filling it with a blue background.

        • 1. Re: else delete interfering with other MCs?
          kglad Adobe Community Professional & MVP

          there's nothing in the code you showed that would remove an object so i assume that's being done in killscreen().  if so, killscreen should be passed mc and removing it.

          • 2. Re: else delete interfering with other MCs?
            shintashi Level 1

            yes killscreen() removes the textbox:

             

             

            ---

            function killscreen(){
                FF2text.removeMovieClip();
                tLabel.removeTextField();
                aLabel.removeTextField();
                bLabel.removeTextField();
            }

             

            ---

             

            oddly enough the glow filter works fine - it stays glowing until the "man" is no longer in contact with the tile/object, and then lights up normally with other tile contacts. I don't understand why one works and the other does not.

            • 3. Re: else delete interfering with other MCs?
              kglad Adobe Community Professional & MVP

              is there a problem after mc is clicked?  if so, make your textfield a child of mc so only that textfield is removed.

              1 person found this helpful
              • 4. Re: else delete interfering with other MCs?
                shintashi Level 1

                attaching the new textbox to the mc would prevent it from interfering with other textbox popups,

                but with proximity to other tiles on different layers several movieclips would be superimposed over the textbox,

                rendering it unreadable in some places.

                 

                edit:

                 

                first tested the attaching system. It produced a textbox that wouldn't delete, and the text (textfields) couldn't be attached and vanished in an instant.

                 

                 

                Then created this:

                ---------

                function zone(mc, zquestion, one, two){
                        if(man._y < mc._y +50 && man._y > mc._y -50 && man._x < mc._x +100 && man._x > mc._x +25){
                        var glowInstance2:GlowFilter = new GlowFilter(0x22FF22, 0.6, 8, 8, 4);
                    mc.filters = [glowInstance2]; //makes kanji signs and so forth light up.
                            mc.onRelease = function(){
                                textscreen(zquestion, one, two);
                            }
                        }else {delete mc.onRelease; mc.filters = null;
                    if(man._y > mc._y +50 || man._y < mc._y -50 || man._x > mc._x +100 || man._x < mc._x +25){
                        killscreen();
                    }
                    
                  
                        }
                   
                    }

                -------

                 

                This had the effect of working as long as only one object was on the screen at a time, whereas in the previous example, if any other object existed on any tile map, it would interfere. This version only interferes with objects on the same tile map. Clearly the reason is because it's checking for everything beyond it's center.

                • 5. Re: else delete interfering with other MCs?
                  shintashi Level 1

                  if(Key.isDown(Key.LEFT) || Key.isDown(Key.DOWN) || Key.isDown(Key.UP) || Key.isDown(Key.RIGHT)){
                      killscreen();    }

                   

                   

                  I wrapped killscreen(); in a series of Keylisteners, which seems to work, but I'd prefer a solution that requires the man t be in collision with NONE of the MCs addressed by the function, but how do I do that?

                  • 6. Re: else delete interfering with other MCs?
                    kglad Adobe Community Professional & MVP

                    store your MCs in an array and when testing, assign a boolean to false and loop through your array elements.  if there's a positive hittest with any array element assign the boolean to true.  when the loop completes if the boolean is still false, there's be a collision with none of the MCs.

                    1 person found this helpful