16 Replies Latest reply on Jul 28, 2009 1:15 PM by kglad

    delete movie clip with movie clip

    03bud

      I want a movie clip to delete a movie clip when one rollsover the other.

        • 1. Re: delete movie clip with movie clip
          kglad Adobe Community Professional & MVP

          a movieclip doesn't normally rollover another movieclip.  are you doing something to move one or or both movieclips so they occassionally overlap or hit each other?  if so, what are you doing to cause that?

           

          eg, are you dragging one movieclip?  are you using a loop of some kind?

          • 2. Re: delete movie clip with movie clip
            03bud Level 1

            One movie clip is on arrow keys  and the other is duplicated by 2.  I can get the movie clip to delete the instance, which is not what I want.  I want it the other way around, the instance to delete the movie clip.

             

            //delete the sun with the cloud
            for (var i = 1; i <= 6; i++)
            {
            if (sun_mc.hitTest (tl["cloud_mc" + i]))
            {
            trace ("the sun hit the cloud");
            tl["cloud_mc" + i].removeMovieClip ();
            }
            }
            }
            Key.addListener (keyListener);

            • 3. Re: delete movie clip with movie clip
              kglad Adobe Community Professional & MVP

               

               

              //delete the sun with the cloud
              for (var i = 1; i <= 6; i++)
              {
              if (sun_mc.hitTest (tl["cloud_mc" + i]))
              {
              trace ("the sun hit the cloud");
              // is sun_mc's depth is less than 0, swap its depth into an unoccupied removeable depth
              sun_mc.removeMovieClip();
              }
              }
              }
              Key.addListener (keyListener);
              1 person found this helpful
              • 4. Re: delete movie clip with movie clip
                03bud Level 1

                Sorry I'm new to this.  This is what I have set for the cloud.  What should I have for the single sun movie clip?

                 

                for (var i = 1; i <= 6; i++)
                {
                duplicateMovieClip ("cloud_mc", "cloud_mc" + i, i);
                _root["cloud_mc" + i]._x = 600 * Math.random ();
                _root["cloud_mc" + i]._y = 200 * Math.random ();
                }

                • 5. Re: delete movie clip with movie clip
                  kglad Adobe Community Professional & MVP

                  if the sun is hit by any of the clouds, do you want to remove the sun?  if yes, use the code i gave.

                  • 6. Re: delete movie clip with movie clip
                    03bud Level 1

                    For the love of me I don't know why it is not deleting, as I'm getting a trace in the output window.

                     

                    Is there anything wrong with this script that I have for the sun or should this script be on the clip.

                     

                    stop ();
                    var tl:MovieClip = this;
                    var distance:Number = 8;
                    var keyListener:Object = new Object ();
                    keyListener.onKeyDown = function ()
                    {
                    if (Key.isDown (Key.LEFT))
                    {
                    sun_mc._x = Math.max (sun_mc._x - distance, 0);
                    //trace ("move left");
                    }
                    else if (Key.isDown (Key.RIGHT))
                    {
                    sun_mc._x = Math.min (sun_mc._x + distance, 580);
                    //trace ("move right");
                    }
                    else if (Key.isDown (Key.UP))
                    {
                    sun_mc._y = Math.max (sun_mc._y - distance, 0);
                    //trace ("move up");
                    }
                    else if (Key.isDown (Key.DOWN))
                    {
                    sun_mc._y = Math.min (sun_mc._y + distance, 570);
                    //trace ("move down");
                    }

                    • 7. Re: delete movie clip with movie clip
                      03bud Level 1

                      Sorry, to answer your question yes I want the sun to disappear when it contacts the cloud and I have used the script you gave me.

                      • 8. Re: delete movie clip with movie clip
                        kglad Adobe Community Professional & MVP

                        as mentioned in my message .3,  sun_mc needs to be at a removeable depth.  is it?

                         

                        you can use sun_mc.getDepth() to check.

                        • 9. Re: delete movie clip with movie clip
                          03bud Level 1

                          I presume it was supposed to go in after sun_mc.removeMovieClip(); or instead of either way it only output the trace.  Would swap movie clip work and how do I apply it.

                          • 10. Re: delete movie clip with movie clip
                            kglad Adobe Community Professional & MVP

                            did the trace output confirm that sun_mc is at a non-removeable depth?  if so, use:

                             

                            sun_mc.swapDepths(put some number here that is a removeable depth and contains no other object);  //  1000000 is probably good.

                            sun_mc.removeMovieClip();

                            • 11. Re: delete movie clip with movie clip
                              03bud Level 1

                              Thank God and You that worked.  But only when I comment out my stars that delete when the sun touches them and work when the other is commented out.  How can I get them all working without one or the other commented out.  I have tried using the swap again.

                               

                              I read that a movie clip placed manually on the stage ( the sun is) cannot be removed  using the removeMovieClip and suggests using the attachMovie or duplicateMovieClip.  Would that be the problem with this?

                              • 12. Re: delete movie clip with movie clip
                                kglad Adobe Community Professional & MVP

                                everything can work as long as your logic is ok.  you want your sun to be deleted when it hits a cloud and you want your stars deleted if they hit the sun.  what else and show your code?

                                 

                                and you read wrong.  objects placed on stage can be removed but only after they are swapped to a removeable depth.  and that's exactly what we've been dealing with in this thread, lately.

                                1 person found this helpful
                                • 13. Re: delete movie clip with movie clip
                                  03bud Level 1

                                  Yes I know we've been swapping, just thought that there might be a shorter and better way.
                                  Script:
                                  var tl:MovieClip = this;
                                  stop ();
                                  var distance:Number = 10;
                                  var keyListener:Object = new Object ();
                                  keyListener.onKeyDown = function ()
                                  {
                                  if (Key.isDown (Key.LEFT))
                                  {
                                  sun_mc._x = Math.max (sun_mc._x - distance, 0);
                                  //trace ("move left");
                                  }
                                  else if (Key.isDown (Key.RIGHT))
                                  {
                                  sun_mc._x = Math.min (sun_mc._x + distance, 575);
                                  //trace ("move right");
                                  }
                                  else if (Key.isDown (Key.UP))
                                  {
                                  sun_mc._y = Math.max (sun_mc._y - distance, 0);
                                  //trace ("move up");
                                  }
                                  else if (Key.isDown (Key.DOWN))
                                  {
                                  sun_mc._y = Math.min (sun_mc._y + distance, 570);
                                  //trace ("move down");
                                  }
                                  //delete the sun with the cloud
                                  for (var i = 1; i <= 6; i++)
                                  {
                                  if (sun_mc.hitTest (tl["cloud_mc" + i]))
                                  {
                                  trace ("the sun hit the cloud");
                                  // is sun_mc's depth is less than 0, swap its
                                  //depth into an unoccupied removeable depth
                                  sun_mc.swapDepths(1000000);
                                  //  1000000 is probably good.
                                  sun_mc.removeMovieClip();
                                  }
                                  }
                                  }
                                  Key.addListener (keyListener);
                                  //delete an instance of the star with the sun  
                                  for (var i = 1; i <= 6; i++)
                                  {
                                  if (sun_mc.hitTest (tl["star_mc" + i]))
                                  {
                                  trace ("the sun has hit the star_mc movieClip");
                                  tl["star_mc" + i].removeMovieClip ();
                                  }
                                  }
                                  }
                                  Key.addListener (keyListener);
                                  // This code duplicates and randomly positions new instances
                                  //of the movieClip star_mc
                                  for (var i = 1; i <= 6; i++)
                                  {
                                  duplicateMovieClip ("cloud_mc", "cloud_mc" + i, i + 6);
                                  _root["cloud_mc" + i]._x = 600 * Math.random ();
                                  _root["cloud_mc" + i]._y = 200 * Math.random ();
                                  }
                                  for (var i = 1; i <= 6; i++)
                                  {
                                  duplicateMovieClip ("star_mc", "star_mc" + i, i);
                                  _root["star_mc" + i]._x =600 * Math.random ();
                                  _root["star_mc" + i]._y = 200 * Math.random ();
                                  }
                                  Well we can discuss adding sound to it some other day!
                                  Cheers!

                                  • 14. Re: delete movie clip with movie clip
                                    kglad Adobe Community Professional & MVP

                                    you're not learning from past mistakes.  the code to check for hittests needs to be in your key listener function:

                                     


                                    var tl:MovieClip = this;
                                    stop ();
                                    var distance:Number = 10;
                                    var keyListener:Object = new Object ();
                                    keyListener.onKeyDown = function ()
                                    {
                                    if (Key.isDown (Key.LEFT))
                                    {
                                    sun_mc._x = Math.max (sun_mc._x - distance, 0);
                                    //trace ("move left");
                                    }
                                    else if (Key.isDown (Key.RIGHT))
                                    {
                                    sun_mc._x = Math.min (sun_mc._x + distance, 575);
                                    //trace ("move right");
                                    }
                                    else if (Key.isDown (Key.UP))
                                    {
                                    sun_mc._y = Math.max (sun_mc._y - distance, 0);
                                    //trace ("move up");
                                    }
                                    else if (Key.isDown (Key.DOWN))
                                    {
                                    sun_mc._y = Math.min (sun_mc._y + distance, 570);
                                    //trace ("move down");
                                    }
                                    //delete the sun with the cloud
                                    for (var i = 1; i <= 6; i++)
                                    {
                                    if (sun_mc.hitTest (tl["cloud_mc" + i]))
                                    {
                                    trace ("the sun hit the cloud");
                                    // is sun_mc's depth is less than 0, swap its
                                    //depth into an unoccupied removeable depth
                                    sun_mc.swapDepths(1000000);
                                    //  1000000 is probably good.
                                    sun_mc.removeMovieClip();
                                    }
                                    }
                                    //delete an instance of the star with the sun  
                                    for (var i = 1; i <= 6; i++)
                                    {
                                    if (sun_mc.hitTest (tl["star_mc" + i]))
                                    {
                                    trace ("the sun has hit the star_mc movieClip");
                                    tl["star_mc" + i].removeMovieClip ();
                                    }
                                    }
                                    }
                                    Key.addListener (keyListener);

                                    // This code duplicates and randomly positions new instances
                                    //of the movieClip star_mc
                                    for (var i = 1; i <= 6; i++)
                                    {
                                    duplicateMovieClip ("cloud_mc", "cloud_mc" + i, i + 6);
                                    _root["cloud_mc" + i]._x = 600 * Math.random ();
                                    _root["cloud_mc" + i]._y = 200 * Math.random ();
                                    }
                                    for (var i = 1; i <= 6; i++)
                                    {
                                    duplicateMovieClip ("star_mc", "star_mc" + i, i);
                                    _root["star_mc" + i]._x =600 * Math.random ();
                                    _root["star_mc" + i]._y = 200 * Math.random ();
                                    }

                                    • 15. Re: delete movie clip with movie clip
                                      03bud Level 1

                                      Not sure what you mean?  But all I had to do was delete a curly bracket just before the second key listener and it worked.

                                       

                                      Thank you!

                                      • 16. Re: delete movie clip with movie clip
                                        kglad Adobe Community Professional & MVP

                                        you're welcome.

                                        1 person found this helpful