14 Replies Latest reply on Mar 17, 2008 6:21 AM by SIPerformance

    selectable area movie clip

    SIPerformance
      My overall goal is to have draggable windows. What I want to do is have a container MC that acts like a window. Inside the container I want to have other MCs that hold loaded content and a title bar. What I want to do is set an area on the container MC as a hit area so I can grab that area and drag the window around but still be able to select buttons inside the container MC.

      I know I can do this by making the container MC a button and setting its hit area but I don't know how or if I can target MCs inside a button. I tried this already but could not reference the MCs in the container from the main time line or from inside the container.


      I hope this is not clear as mud. Any help is appreciated.
        • 1. Re: selectable area movie clip
          rlc5611 Level 1
          Just like a similar post a minute ago - use hitTest with mouse events on the draggable window (or portion thereof) rather than onPress and onRelease handlers and save those for the buttons inside the container.
          • 2. Re: selectable area movie clip
            SIPerformance Level 1
            I will look at the other post, but off hand looking at hitTest I am not sure how I would use it in this instance.
            • 3. Re: selectable area movie clip
              rlc5611 Level 1
              Well in your case since all you want to do is use only a specific part of your container MC to drag with (e.g. the blue bar on a browser), I can't even see why you have a conflict that this would be an issue for you. Make your "area" for dragging a child MC of the container and let it drag its parent (i.e. the container). Just make certain the drag area's depth is the always highest of all the children in the container.
              • 4. Re: selectable area movie clip
                SIPerformance Level 1
                I did do this, but I was having lagging issues (very minor) if you spazed out with the mouse on the screen. I had a barMC in the containerMC and when pressing the bar and dragging it changed the position of the container MC to match.


                I did also go look at the other post
                http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=288&threadid =1346011&enterthread=y

                and found it very helpful. I have decided on a course of action and I thank you for your input!

                P.S. My A.D.D kicked in and I started clicking compulsivly adding more shapes to the aquarium.
                • 5. Re: selectable area movie clip
                  rlc5611 Level 1
                  Having one MC follow another MC around will not give pleasing performance. Been there - done that. So everything you want to drag smoothly must be in the same clip. In your case, what would be easiest is to have the container clip with two children. The child at the higher depth is the drag area and the child at the lower depth is another container. It is in the child container where you put all your MCs/duplicate MCs. Let the child drag the parent which will move everything in unison. For what you want, the hitTest is more complicated than you need. Getting communication and interaction among the clips' timelines is just a matter of finding the correct path. You might also look at setInterval rather than a frame-based event to improve performance.

                  Now what I have been thinking is to modify the script so that bigger fish can eat smaller fish upon hitTest. I'm wondering if there might not be some performance issues if there are too many fish. Maybe I'll try....
                  • 6. Re: selectable area movie clip
                    SIPerformance Level 1
                    Since you have been so hepful maybe I can get one more bit out of you....

                    I am using the hit test on the windows to drag them around (works great, thank you) and now I want the currently selected window to be on top. So what do I use to change the depth of an MC?
                    • 7. Re: selectable area movie clip
                      rlc5611 Level 1
                      A couple of questions:

                      What timeline are you trying to change depths in (_root or a MC, etc.)?

                      Are your windows authored or created dynamically?

                      Are you using or ever plan to use Flash components?

                      BTW the short answer is swapDepths()
                      • 8. Re: selectable area movie clip
                        SIPerformance Level 1
                        A) _root
                        B) Both (curious why and what problems I am going to hit)
                        C) Yes, down the road


                        I have discovered, after a little due diligence, the swapDepths(). I guess I was looking for a way to set my MC to getNextHighestDepth(). But after thinking about it, that would leave a depth empty and maybe that is not allowed. So, I am using a highDepth var and testing and setting it to keep track of which window I need to swap with.
                        • 9. Re: selectable area movie clip
                          rlc5611 Level 1
                          This is the simple way but, if you overlap clips, you will see that it is visually problematic.
                          • 10. Re: selectable area movie clip
                            rlc5611 Level 1
                            But a better approach is to keep track of all your depths. It is slightly more script but much better looking. There may be a more efficient way than what I have attached but this does work. Try overlapping clips and note the difference.
                            • 11. Re: selectable area movie clip
                              rlc5611 Level 1
                              Okay I just saw your post. If you use the last script and keep track of all your depths in an array, you should be able to avoid all problems. If you create a new clip dynamically, just always push its depth into the array.

                              I can't see any reason why you can't work with both authored and dynamically created depths this way. Authored clips have negative depths but the layering order will still be the same.

                              Flash Components are problematic for using getNextHighestDepth() in the _root timeline. There are alternative solutions to get around this. One solution is to make your own depth manager and not use getNextHighestDepth(), another is to work in a timeline other than the _root as getNextHighestDepth() only stuffs up badly in the root. Yet another possibility is never use Flash components. Either make your own or go buy 3rd party.

                              Having said that, if you never intend to remove any of your clips, you should not have a problem anyway.
                              • 12. Re: selectable area movie clip
                                SIPerformance Level 1
                                thanks a bunch!
                                • 13. Re: selectable area movie clip
                                  Level 7
                                  This can be as easy as calling startDrag when a buttons onPress method is
                                  called...
                                  For example, say you have a container clip - 'dialog'. Within dialog there
                                  is a bar, at the top, it's a movieClip too, with an instance name of
                                  'dragger'
                                  On the main timeline then:

                                  dialog.dragger.onPress = function(){
                                  this._parent.startDrag();
                                  }
                                  dialog.dragger.onRelease = dialog.dragger.onReleaseOutside = function(){
                                  stopDrag();
                                  }

                                  HTH
                                  --
                                  Dave -
                                  Head Developer
                                  http://www.blurredistinction.com
                                  Adobe Community Expert
                                  http://www.adobe.com/communities/experts/


                                  • 14. Re: selectable area movie clip
                                    SIPerformance Level 1
                                    OK you get the prize for the easiest solution. Thats what I love about this stuff, I've got 3 very different ways to do the exact same thing.

                                    Thank You.