22 Replies Latest reply on Jun 22, 2009 8:28 AM by brandonspeed

    Drag & Drop Problem

    brandonspeed

      Hiya -

      Im still new to Flash and need some urgent help (picture attached).

       

      This will probably seem like a basic problem to a Flash guru but if anybody has the answer I'd appreciate it greatly as Im stumped!

       

      I have an image that has been converted to a MC and is on Frame 1. On the MC image I have placed the following basic code:

      on(press){

         startDrag(this);

      }

      on(release){

         stopDrag();

      }

       

      I have also set frame 1 to stop.

       

      Right, so that WORKS perfectly fine. But the problem is that I have a MC in the corner of this MC image (and it basically serves as a 'zoom' button') and this opens another set of frames when clicked on but I cant seem to get this new MC' actionscript to work AND 'drag and drop' with the MC below it. I only seem to be able to get the MC (zoom button) to work if its on its own.

       

      How can I get a MC with actionscript  to work on top of another MC? And drag and drop both together in their exact corresponding positions?

      Help appreciated!

      B

        • 1. Re: Drag & Drop Problem
          Ned Murphy Adobe Community Professional & MVP

          If I understand the scenario, what you can do is put both of those things into another movieclip.  You will still code the image mc, but you will code it to drag the parent movieclip.  That way, both pieces wthin the containing mc will have clear access to the mouse and both will be moved together.

           

          on(press){

             startDrag(this._parent);

          }

          • 2. Re: Drag & Drop Problem
            brandonspeed Level 1

            Hi - thanks for the response.

             

            I have spent about an hour trying to get your suggestion to work - Im about half way there - both the movie clips are now joined into a parent movie clip and drag together which is great  - unfortunately however the problem now is that the action script in the corner zoom movie clip (which is now inside the parent movie clip) does not work at all.

            The parent movie clip AS is set to: 

            on(press){

               startDrag(this);

            }

            on(release){

               stopDrag();

            }

             

             

             

             

            The zoom movie clip inside the parent is set to:

            on (release) {

            gotoAndPlay(2);

            }

             

            Im guessing the movie clip within the parent is 'overruled' by the parent? as they essentially have the same onrelease function? How do I get around this?

             

            So I basically haven't solved this problem - any more ideas (please)?

            PS. I also tried making them all buttons and that didnt work either.

            B

            • 3. Re: Drag & Drop Problem
              Ned Murphy Adobe Community Professional & MVP

              Not any new ideas, just the one I offered.  Keep the code assigned to the image inside the parent movieclip, but change the code to drag the parent as I showed.  All you really needed to do to make this change was to modify the code on the image to what I showed (assuming my retargeting was valid), and then select the two pieces and convert them into a movieclip (right click, convert to symbol).

               

              Having the code on the containing clip does block out the access to anything inside it.  So having the two items inside carry the code solves this.  The items inside should be separate items from each other.

              • 4. Re: Drag & Drop Problem
                brandonspeed Level 1

                I have actually just got it to work - thanks for your help - the following code of yours really helped get the 2 MC's moving: on(press){

                   startDrag(this._parent);

                }

                 

                However you might be surprised to learn that the 'onPress' function on the parented zoom and image movie clips ONLY WORK together when the parent is converted to a 'graphic' element! For some reason the 'zoom' actionscript inside the parent did not work at all when parented up. But in exasperation i converted it to a 'graphic' and hey presto - it worked! PROBLEM SOLVED.

                Now the fun starts (I might be back...)

                Thanks again.

                B

                • 5. Re: Drag & Drop Problem
                  Ned Murphy Adobe Community Professional & MVP

                  Did you remember to remove the code from the parent mc?

                  • 6. Re: Drag & Drop Problem
                    brandonspeed Level 1

                    Yip. No code on the parent - only within it. And it works perfectly well as a graphic element - just not as a MC or BTN (can't explain that really? But hey, if it works - it works)

                     

                    I'm going to crack on and convert the rest of my portfolio images using the same code and will post a link for my new website in a couple weeks when I'm done.
                    Cheers mate - THANKS.

                    • 7. Re: Drag & Drop Problem
                      Ned Murphy Adobe Community Professional & MVP

                      Yeah, it wouldn't work inserting it into a button because a button automatically enmouses (new word) any content within it, and you cannot apply code to elements in buttons.  But it should work with a movieclip, though I suppose it's possible you have something going on with your zoom that interferes.

                      • 8. Re: Drag & Drop Problem
                        brandonspeed Level 1

                        I've encountered a slight problem with this code unfortunately....

                         

                        As discussed above I created an image movieclip (with drag and drop functionality), and a button (which acts as a zoom). Both of them obviously use actionscript. I then bonded them together in a parent movieclip with no code in it so that the drag and drop would drag the parent. Ok that all works perfectly fine and the 2 bits drag together as one and even perform their action script duties prefectly fine.

                         

                         

                        The problem is......

                        If I create a scenario where I have more objects that use the same drag and drop script used above: on(press){

                           startDrag(this._parent);

                        }

                        on(release){

                           stopDrag();

                        }

                         

                        ...they all seem to drag in unison - all the parent MCs together. So if I have a page (as attached) that has 7 parent MC's they will all drag around together instead of individually. This is obviously not really what I had in mind. I have made separate MC's for all the items exactly the same way as I did for the first item - and even tried putting them on different layers but alas that did not work either and they all continue to drag together. (see attached)

                        Any solutions?

                        Bran

                        • 9. Re: Drag & Drop Problem
                          C-Rock Level 2

                          I think you'll have to create a onPress function for each clip if that's what you're asking. The reason they all drag is because you say this._parent with means the main stage or parent movie clip is dragging not each one.

                          • 10. Re: Drag & Drop Problem
                            Ned Murphy Adobe Community Professional & MVP

                            I can't be sure of what you've done, so I created a quick sample you can look at--I've saved it as a Flash 8 file.

                             

                            http://www.nedwebs.com/Flash/dragmcs.fla

                            • 11. Re: Drag & Drop Problem
                              brandonspeed Level 1

                              Thanks for the sample - what does the code do that you have used on your buttons?

                              on(rollOver){

                              trace("btn inside");

                              }

                               

                              I substituted this code with:

                              on (release) {

                              gotoAndPlay(2);

                              }

                               

                              This code needs to play a sequence on Frame 2. However my code does not work and goes back to the problem above (not being able to put two 'onRelease' scripts on the same MC.

                               

                              I thought that I got around this by converting the MC to a Graphic Element however then every MC with the code startDrag(this._parent); seems to move EVERYTHING on(press) in the stage.

                               

                              I have saved a new version of your file for you (attached) where you can see that the script does not work - I only applied it to the 1st top left button.

                              (This has save as a Flash C8 file...)

                              B

                              • 12. Re: Drag & Drop Problem
                                brandonspeed Level 1

                                Sorry - try:

                                ftp.cd.co.uk/pub/incoming/dragmcs2.fla.zip

                                • 13. Re: Drag & Drop Problem
                                  Ned Murphy Adobe Community Professional & MVP

                                  The purpose of the code on my button was simply to demonstrate that the button still works while sharing a room with the mc that has the drag code assigned to it.

                                   

                                  If you have converted the container to a graphic symbol, then you have taken away any functionality it might have had as a movieclip.  Graphic symbols essentially have no life, they are mere occupiers of space that cannot be controlled with actionscript (they have no instance identity).

                                   

                                  I looked at the changed version you made and it works for what you're telling it to do.  You probably just don't realize what you've told it to do.  The button is telling the movieclip it is sitting in to gotoAndPlay(2)... but the movieclip it is sitting in doesn't have a frame 2.  Beyond that I don't really know what you are trying to do.

                                   

                                  I can see that you have added another frame to the main timeline, so if that's where you meant in terms of going to frame 2, then for the button you would need to use either...

                                   

                                  on (release) {
                                  _parent.gotoAndPlay(2);
                                  }

                                   

                                  OR

                                   

                                  on (release) {
                                  _root.gotoAndPlay(2);
                                  }

                                  • 14. Re: Drag & Drop Problem
                                    brandonspeed Level 1

                                    That's it! That code works. I guess I assumed it would play frame 2 of the parent - I now realise I needed to have the word 'parent' (or root) in the code.

                                    Ace.

                                    Thanks again.

                                    • 15. Re: Drag & Drop Problem
                                      Ned Murphy Adobe Community Professional & MVP

                                      You're welcome.

                                      • 16. Re: Drag & Drop Problem
                                        brandonspeed Level 1

                                        Now to add a bit of style to my drag and drop code - Im using it on my portfolio site and all the items I have designed can be dragged around the stage and selected for various actions. I was wondering if it isn't too much to ask already - seeing that I am now cracking away at this site with the new code - I was wondering if it were perhaps possible to add a something to the parent code that when onPress the parent 'moves to the top'.

                                        This is quite important if there is a group of objects overlapping each other and the selected parent object is on the bottom of a layer with other objects blocking it from view. I imagine it is something like 'on(press).Bring to Front' or something to that effect?

                                         

                                        Ned, I know that you insisted that I was to leave the 'parent MC' without any actionscript - however I imagine that this 'bring to front' code would maybe be stuck onto the parent?

                                         

                                        As usual - any help much appreciated.

                                        Bran

                                        • 17. Re: Drag & Drop Problem
                                          Ned Murphy Adobe Community Professional & MVP

                                          Nope, if you stick onPress code in the parent, you're back to losing touch with the stuff inside it.

                                           

                                          Rather than hand you a solution on this one, I'd rather identify the tools you might use.  Read up on them in the help docs and see if you can think thru how they might be put to use.  You're already using one of them in the way it should be used (onPress), so look into getNextHighestDepth() and swapDepths().  When you run into a problem, start a new posting that describes where you are, what you're using for code, and what's not working.

                                           

                                          You may get someone else jumping in with a solution here, which I can't and wouldn't try to control, but I think it's better if you learn new things by researching and trying to solve them.  You can't really learn much from handouts--mostly because learning takes time and effort and handouts eliminate the need for the effort and usually the drive to pursue it.

                                          1 person found this helpful
                                          • 18. Re: Drag & Drop Problem
                                            brandonspeed Level 1

                                            I took your advice and had a hunt through the sample sheets that are in the Flash 8 'Samples & Tutorials' folder...and found exactly what I was after: on (press) {

                                            //Start Dragging Movieclip Behavior

                                            startDrag(this);

                                            //End behavior

                                            //Bring to Front Behavior

                                            mx.behaviors.DepthControl.bringToFront(this);

                                            //End behavior

                                            }

                                             

                                            Works a charm. And I didn't even have to ask anybody for help!

                                            thanks again man.

                                            B

                                            • 19. Re: Drag & Drop Problem
                                              Ned Murphy Adobe Community Professional & MVP

                                              You're welcome... don't it feel great solving something!

                                              • 20. Re: Drag & Drop Problem
                                                brandonspeed Level 1

                                                Hi Ned - as it turns out I may need your help again if you don't mind.

                                                 

                                                Still relating to this drag and drop issue:

                                                Well...I went away and designed half my site only for me to decide that instead of having a fixed width window pop open up for each of my images on press, I would instead just create 2 frame movie clips of each of those images, with a button in the corner of each to activate them *I was inspired by the following site: http://www.donnieluu.com/_work/other/_helmet/helmet.html).

                                                 

                                                With the drag and drop working fine to start exactly how we coded it in the above description, I now have the problem that the drag and drop item keeps moving back to it's original starting place when the movieclip is played. This is not how it should work - it needs to activate in the new position if moved!....any ideas as to the code I need to use?! It's a very unique problem and unfortunately I cant find an answer to this as yet.

                                                 

                                                I have attached a basic mock-up fla file of the code Im using. Any code tips/hints/suggestions would be much appreciated!

                                                Thanks

                                                B

                                                • 22. Re: Drag & Drop Problem
                                                  brandonspeed Level 1

                                                  Trying to get this site to upload my zip file....