14 Replies Latest reply on Jan 20, 2009 8:47 AM by kglad

    swapDepths problems

    BeniRose
      I'm trying to do a swapDepths, which was working before, but suddenly stopped. I'm trying to swapDepth with _parent.getNextHighestDepth(), but even if I hardcode the number I trace in it's not working. I have two separate objects I'm using, but this shouldn't be a problem, right?
        • 1. Re: swapDepths problems
          kglad Adobe Community Professional & MVP
          do you have any components in your swf? have you used the trace() function to see what you're doing?
          • 2. Re: swapDepths problems
            BeniRose Level 1
            I don't have components, but I have two external .as files that I'm instantiating objects with, which is where the swapDepth is happening. Let me see if I can explain this without convoluting the details.

            I have two .as files, ItemGroup, and ItemBox. ItemGroup get passed a parent_mc when it is instantiated from my SWF (in this case, it's _root) and creates a new MC called "group_mc" on the parent_mc level (e.g. parent_mc.createEmptyMovieClip("group_mc",parent_mc.getNextHighestDepth());).

            ItemGroup also has a function called addItem, which instantiates a new ItemBox, passing group_mc to ItemBox, which is where each new itemBox will create it's MovieClips. So itemBox creates an "itembox_mc" movieclip that is attached to group_mc, and all the MCs within itemBox are attached to itembox_mc. (It also appends the depth to the mc name as to not have two mc's with the same name, I just left this out for simplicity).

            So so far we have: _root.group_mc.itembox_mc, where group_mc was created within ItemGroup and itembox_mc was created within ItemBox. ItemGroup was the only class instantiated from my SWF, with ItemGroup.addItem being called from the swf as well. Hopefully this all makes sense so far.

            Now here comes the swapDepth. I have it in ItemBox that the itembox_mc is being referenced by a private variable called "_mc", so on instantiation I have _mc.onRelease = this.open, which calls a function within ItemBox called "open()". In the open function, I have a call:

            _mc.swapDepths(_mc._parent.getNextHighestDepth());

            I thought the reason this wasn't working was because _mc._parent is a MovieClip that was created in a different class, but even when I replace _mc._parent.getNextHighestDepth with a number I know is not being used, it still doesn't work. Also, I can trace everything and it comes out fine:

            trace(_mc.getDepth());
            trace(_mc._parent.getNextHighestDepth());
            _mc.swapDepths(_mc._parent.getNextHighestDepth());
            trace(_mc.getDepth());

            will output:

            1
            4
            1

            When if it worked it would output 1,4,4, which it doesn't even do if I hardcode the 4 in the swapDepth. So yeah, sorry to drop all of that on you, but hopefully you can help me out because I'm really in a bind! Thanks!
            • 3. Re: swapDepths problems
              kglad Adobe Community Professional & MVP
              what's trace(typeof(_mc)) reveal? and if that's a custom class, does that custom class subtype MovieClip? and it yes to both, are you over-writing the swapDepths() method in your custom class?
              • 4. Re: swapDepths problems
                BeniRose Level 1
                That trace would output movieclip. _mc is a private variable in ItemBox that is a reference to the MovieClip that is created when it's instantiated. I'll attach the first few lines of the constructor for ItemBox so you can see what I mean.


                • 5. Re: swapDepths problems
                  kglad Adobe Community Professional & MVP
                  do your create more than one instance of ItemBox?
                  • 6. Re: swapDepths problems
                    BeniRose Level 1
                    Yes, ItemGroup will call addItem somewhere between 3 to 5 times (it will actually be driven by XML when it's all finished), but as you can see in the createEmptyMovieClip, I append their original depth to their name as to keep from having two ItemBoxes with the same name.
                    • 7. Re: swapDepths problems
                      kglad Adobe Community Professional & MVP
                      and where's the code that swaps depths? ie, are you sure _mc is a unique reference in the scope where you (try to) swap depths?
                      • 8. Re: swapDepths problems
                        BeniRose Level 1
                        Well, there is a private variable called "_mc" in both ItemGroup and ItemBox, but that shouldn't mean anything. But the function that contains the swapDepth is within ItemBox, and I'm referencing _mc in a bunch of other lines immediately after the swapDepth call without any ambiguity as to which _mc it is referencing. Each instance of ItemBox only has one private variable "_mc".
                        • 9. Re: swapDepths problems
                          BeniRose Level 1
                          If you would like, I can send you the code/project file. I'm working in CS4 though, so I'm not sure if the project file will work, since CS3 project files don't seem to open in CS4.
                          • 10. Re: swapDepths problems
                            kglad Adobe Community Professional & MVP
                            i have cs4 but i rarely download files unless i'm hired to solve the problem.

                            and i can't see any way to reconcile your problem without checking your files. maybe someone else can help.
                            • 11. Re: swapDepths problems
                              BeniRose Level 1
                              Alright well thanks for your time. Glad it's not something surprisingly simple that would make me feel dumb, but at the same time I sort of wish it was, so I could just move forward with this project. If anyone else has any ideas on why this is happening or wants me to send them files, please let me know. I'm going to try to take the ItemGroup out of the equation and see if it works again, cause it worked like that before.
                              • 12. Re: swapDepths problems
                                kglad Adobe Community Professional & MVP
                                you're welcome. and good luck!
                                • 13. Re: swapDepths problems
                                  BeniRose Level 1
                                  I figured it out and it turns out it was something rather silly. You were SOOO close when you asked if I was creating more than one instance of ItemBox. As I said, I was appending getNextHighestDepth to the ItemBox's _mc name to keep from multiple MovieClips on the same level with the same name, but I wasn't doing that with my ItemGroups, so when I was creating two ItemGroups, they both had a _root.group_mc MovieClip, which were conflicting with eachtoher. I'm not really sure why it was causing the errors it was causing, or why Flash even let me create a second MovieClip with the same name (I remembered in previous versions, if you did this, the original MovieClip would disappear and be replaced by the new one, but this time they were both there) but when I fixed it, the swapDepth worked flawlessly. Thanks for all you guidance though, it helped me get my head in the right place!
                                  • 14. Re: swapDepths problems
                                    kglad Adobe Community Professional & MVP
                                    you're welcome.