22 Replies Latest reply on Mar 3, 2008 1:35 AM by rlc5611

    removeMovieClip not working

    Andra Veraart Level 1
      Hi there,

      I built a website for our company, but because my boss kept adding stuff as I was building, the navigation-function became a total mess. On top of that, the need has risen to make the site multi-lingual, and I would like to get the back-button and deep-linking to work properly.

      So, I decided to rewrite the navigation-function using the exanimo stateManager. The site structure basically has two levels: Six main sections (L1), most of which have subsections (L2). All these "pages" are library items that get attached to a holder MC (L0). So for instance, the first page is built by attaching "home_NL" to L0 and calling it L1, and then attaching "home_welkom_NL" to L1 and calling it L2.

      This all works fine, until I've clicked “Voices”. If I click a section after that, the L0 gets faded out, but L1 is not removed. And since the function then tries to attach a new library item as L1 and will not continue until it is loaded, navigation simply hangs.

      Unfortunately “luister_NL”, which is loaded when you click “Voices”, is a fairly complex movie clip (by my standards, at least). It allows the visitor to listen to samples of our voice-talents based on language, style and gender. These can also be selected and “ordered” through a form.
      Something in this movie clip is preventing Flash from removing it from the stage, but I can’t figure out what.

      I’ve uploaded the .fla so you can check it out if you want.

      Any suggestions on what could be causing this behaviour would be very welcome.
      Thanks in advance!

      Yours,
      Andra
        • 1. Re: removeMovieClip not working
          kglad Adobe Community Professional & MVP
          your movieclip must not be at a depth that's removable (probably because you're using components and getNextHighestDepth() ). to remedy, use swapDepths() to move your movieclip to a removable depth and then apply removeMovieClip().
          • 2. Re: removeMovieClip not working
            Andra Veraart Level 1
            quote:

            Originally posted by: kglad
            your movieclip must not be at a depth that's removable (probably because you're using components and getNextHighestDepth() ). to remedy, use swapDepths() to move your movieclip to a removable depth and then apply removeMovieClip().


            I already came across that pitfall while googling about this problem. That's why I use the following code (copied from a website I can't remember right now):

            var mTemp:MovieClip = _root.L0.getInstanceAtDepth(0);
            _root.L0.L1.swapDepths(0);
            _root.L0.L1.removeMovieClip();
            if (mTemp != undefined) { mTemp.swapDepths(0); }

            It does move the MC to the proper depth, but still it doesn't get removed. Note that other MC's that are attached to exactly the same MC with exactly the same code DO get removed. This problem is specific to ONE library item.

            Thanks again for any insight.

            Yours,
            Andra
            • 3. Re: removeMovieClip not working
              kglad Adobe Community Professional & MVP
              use trace(_root.L0.L1) after your removeMovieClip() statement.
              • 4. Re: removeMovieClip not working
                Andra Veraart Level 1
                Now this is weird. I already had that trace in my code, and was about to post the results here, when I noticed I was tracing the depth at the wrong point in my code. I traced it before the swap, which always gave me 0.

                Here's a part of my current code:

                var mTemp:MovieClip = _root.L0.getInstanceAtDepth(0);
                trace("mTemp = "+mTemp);
                trace("mTemp.getDepth() = "+mTemp.getDepth());
                trace("_root.L0.L1 = "+_root.L0.L1);
                trace("_root.L0.L1.getDepth() = "+_root.L0.L1.getDepth());
                _root.L0.L1.swapDepths(0);
                _root.L0.L1.removeMovieClip();
                if (mTemp != undefined) { mTemp.swapDepths(0); }
                trace("_root.L0.L1 = "+_root.L0.L1);
                trace("_root.L0.L1.getDepth() = "+_root.L0.L1.getDepth());

                When I move from, for instance, "People" to "News" i get the following output:
                mTemp = _level0.L0.L1
                mTemp.getDepth() = 0
                _root.L0.L1 = _level0.L0.L1
                _root.L0.L1.getDepth() = 0
                _root.L0.L1 = undefined
                _root.L0.L1.getDepth() = undefined

                But when I move from "Voices" to any other section i get this output:
                mTemp = _level0.L0.L1
                mTemp.getDepth() = 0
                _root.L0.L1 = _level0.L0.L1
                _root.L0.L1.getDepth() = 0
                _root.L0.L1 = _level0.L0.L1
                _root.L0.L1.getDepth() = -32769

                It seems as though trying to remove the luister_NL MC moves it to depth -32769.

                Any ideas?

                Yours,
                Andra

                • 5. Re: removeMovieClip not working
                  rlc5611 Level 1
                  Negative depths are some of those depths that cannot be removed.

                  I think that Flash's depth manager sometimes takes a few nanoseconds to get properly caught up and remember where everything should be. If it were me, I would try putting in a slight delay after swapping the depth and then trying to remove it.
                  • 6. Re: removeMovieClip not working
                    rlc5611 Level 1
                    Or maybe better said, try implementing a delay before tracing the depth. I have seen before where removed movie clips can temporarily go through the depth you are seeing before disappearing altogether.
                    • 7. Re: removeMovieClip not working
                      kglad Adobe Community Professional & MVP
                      your code makes no sense. you're taking a movieclip that's at depth 0 and instead of just removing it, you're going through all sorts of gyrations as if the movieclip were at a non-removable depth. and when the movieclip you want to remove is at depth 0 and then you try and swap it with itself, you have nonsense code.

                      you only need to use swapDepths() when the movieclip that you want to remove is at a non-removable depth. and then you don't need to go through all those gyrations to remove it. just swap it with an available removable depth. there are over 1 million of them.
                      • 8. Re: removeMovieClip not working
                        rlc5611 Level 1
                        I also wanted to clarify that I've only experienced that temporary negative depth problem when trying to replace content in a Flash component (specifically the Scrollpane in my case).
                        • 9. Re: removeMovieClip not working
                          kglad Adobe Community Professional & MVP
                          i think using the depth manager (when you're using components) solves all the depth problems caused by ill-behaved components.
                          • 10. Re: removeMovieClip not working
                            rlc5611 Level 1
                            I can't say because I stopped using components. But I remember there was a problem with the Scrollpane in both Flash 6 and 7 where, I was trying to replace the contents of the pane but, because of flaws with the pane, I needed preloader code to ensure the content was loaded so that I could redraw/refresh the pane afterward. So after removing the previous content, I immediately began checking to see if the content was loaded, loading or undefined. What I found was that the recently removed content still existed for a brief instant at an obtuse negative depth and it was the same negative depth every time. So removing the content didn't simply make it vanish - it first changed its depth from positive to negative and then to undefined - kind of like flushing a toilet I guess. I can't say for sure. But rather than go insane trying to solve the problem, I gave up components.
                            • 11. Re: removeMovieClip not working
                              kglad Adobe Community Professional & MVP
                              i don't blame you. i almost never use components. but when i have to complete as partial project that's already set-up with components, i usually keep them and deal with the problems.
                              • 12. Re: removeMovieClip not working
                                Andra Veraart Level 1
                                The depth-swapping code was only added because I ran into this problem, and read somewhere this might be the solution. But since it didn't solve the problem, I might aswell remove it.
                                So here's the new code, this time without any depth swapping:

                                trace("_root.L0.L1 = "+_root.L0.L1);
                                trace("_root.L0.L1.getDepth() = "+_root.L0.L1.getDepth());
                                _root.L0.L1.removeMovieClip();
                                trace("_root.L0.L1 = "+_root.L0.L1);
                                trace("_root.L0.L1.getDepth() = "+_root.L0.L1.getDepth());

                                The problem remains, and here's the output:

                                _root.L0.L1 = _level0.L0.L1
                                _root.L0.L1.getDepth() = 0
                                _root.L0.L1 = _level0.L0.L1
                                _root.L0.L1.getDepth() = -32769

                                rlc5611 mentioned having had problems with depths while using components. The MC that won't be removed, is the only one that does contain components (radio buttons and combo boxes). Could this be cause of this problem.

                                And if so, can anyone take a guess at why that exact same MC can be removed in the old, messy version currently still running at eurovoice.nl?

                                Thanks again for taking time to look into this problem. If I can solve this issue, I can start translating the site, and try and deliver a better user experience. Until then I'm stuck.

                                Yours,
                                Andra

                                • 13. Re: removeMovieClip not working
                                  kglad Adobe Community Professional & MVP
                                  is L0 a component? is L1 a component?
                                  • 14. Re: removeMovieClip not working
                                    Andra Veraart Level 1
                                    L0 is an empty movie-clip that sits on the stage from the beginning. During navigation I attach a library item to L0, and name it L1.
                                    One of the library items that can get attached is luister_NL, the mc that once attached won't let itself be removed. This library item is a movie clip that contains a few components, i.e. radio buttons and combo box.

                                    Attached is my full navigation function, maybe I did something stupid there, though it works for every library item except luister_NL.

                                    Thanks again!
                                    Andra
                                    • 15. Re: removeMovieClip not working
                                      rlc5611 Level 1
                                      You are getting distracted by tracing the depth and getting -32769. I made a simple movie and created one clip with components and two without components and attached and removed them all successfully. In each case I traced the depth immediately after removal. The ones without components traced undefined for their depths while the one with components traced -32769 immediately after the removal. But I placed a separate button on the stage just to check the depth again a second later and, after that delay, the depth did come up undefined. That is what I expected because components just do this for some reason. Components themselves are very complex and there is a lot that has to be cleaned up.

                                      So it does look like Flash is trying to remove the clip but I think you are so focused on this unimportant depth that you have stopped looking for the real problem. I'm certain that the fix is very simple.
                                      • 16. Re: removeMovieClip not working
                                        rlc5611 Level 1
                                        Okay my button I used to remove the clip with components was named b6. This traces:

                                        0
                                        -32769
                                        undefined

                                        So even a 1 millisecond delay is enough for Flash's depth manager to straighten itself out.
                                        • 17. Re: removeMovieClip not working
                                          rlc5611 Level 1
                                          The obvious didn't occur to me but the fact that you can even trace a depth of -32769 is proof that the movie clip is being removed. I think what is happening is that you remove L1 and then immediately use L0.getNextHighestDepth() to attach a new movie. Since there is no delay between the removal and the getNextHighestDepth, for a brief instant, getNextHighestDepth woud return -32768 (-32769 + 1). Whatever is attached at a depth of -32768 could not later be removed without using swapDepths.

                                          I only brielfy looked at your script but I think this is the killer combination. I suggest you implement a delay between removing the L1 clip and then trying to attach another one or else avoid using getNextHighestDepth in that particular clip.
                                          • 18. Re: removeMovieClip not working
                                            rlc5611 Level 1
                                            Or maybe even a simpler fix is to simply create an empty movie clip in L0 with nothing in it at a depth of 0 prior to doing anything at all in your movie. Such as:

                                            _root.L0.createEmptyMovieClip("depth_holder",0);

                                            Just leave that empty clip holder there and never remove it.

                                            This would ensure that regardless of what happened with the depth manager when removing those nasty offensive component clips, getNextHighestDepth() would always return a positive number.

                                            Okay I have been trying to test this and it is strange. What appears to be happening is that the component clip does leave a negative depth upon removal for an instant which confuses getNextHighestDepth but what is more is that this doesn't seem to confine itself only to the component clip. I can get this negative depth periodically even using a clip without components although the component clip does it consistently. So it seems that I can create two clips of the same name at different depths.

                                            Definitely using getNextHighestDepth() immediately after removeMovieClip() seems to be quirky.
                                            • 19. Re: removeMovieClip not working
                                              rlc5611 Level 1
                                              I have been testing the removeMovieClip/getNextHighestDepth combination several ways.

                                              1) I tried in a movie with no components or clips with components in the library. getNextHighestDepth never seems to fail to function correctly.

                                              2) I tried the same thing but with components in the library but never being attached. Again, getNextHighestDepth doesn't seem to fail.

                                              3) Same tes as #2 but attaching the clip with components. Once that clip is attached, getNextHighestDepth becomes erratic and will randomly fail on any attached clip.

                                              Is there any reason why you could not do this?
                                              • 20. Re: removeMovieClip not working
                                                Andra Veraart Level 1
                                                Thanks rlc5611! The delay works! I'm using the following code:

                                                attachL1 = function(newL1){
                                                _root.L0.attachMovie(newL1, "L1", _root.L0.getNextHighestDepth());
                                                some more code here...
                                                }
                                                setTimeout(attachL1, 1, newL1);

                                                And it works like a charm. Interesting results you found there. Guess I'll think twice before using components next time.

                                                Thank you both again for taking this time. This problem was kinda gnawing at me, and was keeping me from moving on with this project.

                                                Yours,
                                                Andra
                                                • 21. Re: removeMovieClip not working
                                                  Andra Veraart Level 1
                                                  quote:

                                                  Originally posted by: rlc5611
                                                  Or maybe even a simpler fix is to simply create an empty movie clip in L0 with nothing in it at a depth of 0 prior to doing anything at all in your movie. Such as:

                                                  _root.L0.createEmptyMovieClip("depth_holder",0);

                                                  Just leave that empty clip holder there and never remove it.


                                                  Just wanted to let you know that I tried this first, but it didn't work for me. That's why I went for the setTimeout option.

                                                  Yours,
                                                  Andra
                                                  • 22. Re: removeMovieClip not working
                                                    rlc5611 Level 1
                                                    You are right. Placing the empty movie clip holder doesn't help because there is still a brief instant in which getNextHighestDepth doesn't function properly even if there are other clips at depths within the same one from which you are removing. I just hadn't tested it completely. It is interesting that the problem persists with other "normal" clips even well after the clip with components is removed. Flash components have always been buggy. I wonder if they have improved in CS3.

                                                    Also be aware that depth management in the root will change when you load that clip with components. When you load that clip, Flash will create two movieclips in the _root named "reserved" at depth 1048575 and "focusManager" at depth 1048574 and those clips will persist even after you remove the clip with components. Those two clips are always created in the _root regardless of how far nested the component(s) is. (at least as far as Flash 8 - I can't speak for CS3 because I haven't spent much time with it.)

                                                    You may only remove clips whose depths are within the range 0 - 1048575 inclusive. The fact that you coud not remove a clip meant that the clip had to be at a depth that was unremoveable so kglad had it pegged it early.