5 Replies Latest reply on Jun 14, 2011 11:26 AM by kglad

    movieclip becomes visible and attached to cursor

    learner102

      I have a simple escape game almost finished but want to try something different.  I already have movieclips on the stage when clicked become (._visible=false;) and the inventory mc, visible=true.  Then i can drag the inventory mc's around to interact with other parts of the game.

       

      My request (hopefully answered simply) is help on having the inventory mc already attached to the cursor (onPress?) when the mc on the stage is clicked.  Basically the inventory mc is to be in a draggable state automatically then you move it to the inventory area or it snaps back to its predetermined location which is what it does now.  Hope this is clear enough.  Thanks for any help.

        • 1. Re: movieclip becomes visible and attached to cursor
          kglad Adobe Community Professional & MVP

          apply startDrag() to your inventory mc when you it to start dragging.

           

          inventory_mc.startDrag();  //<- use the appropriate mc name

           

           

          apply stopDrag() when you want it to no longer drag:

           

          inventory_mc.stopDrag();

          • 2. Re: movieclip becomes visible and attached to cursor
            learner102 Level 1

            Thanks for the reply.  The inventory mc already has a draggable function to it:

             

            emptyBowlInventory_mc.onPress=function()
            { emptyBowlInventory_mc.startDrag();
            }
            emptyBowlInventory_mc.onRelease=function()
            { if(emptyBowlInventory_mc.hitTest(backGround_mc))
            { emptyBowlInventory_mc.stopDrag();
            emptyBowlInventory_mc._x=9.3;
            emptyBowlInventory_mc._y=4.7;
            }
            }

             

            But the drag initially begins from the x and y locations in the script above.  I want the inventory mc to be already be attached to the mouse when it first appears and releasing the inventory mc would send it back to x and y.  Then you can drag the inventory mc as normal.  Here is the script that allows the inventory mc to show:

             

            emptyBowl_mc.onPress = function() {
            ebVisible = false;
            emptyBowl_mc._visible=ebVisible;
            _root.inv_mc.emptyBowlInventory_mc._visible=true;
            }

             

            Thanks for any suggestions.

            • 3. Re: movieclip becomes visible and attached to cursor
              kglad Adobe Community Professional & MVP

              i don't understand the problem.  when you want something to start dragging, apply startDrag().

               

              if you want it _root.inv_mc.emptyBowlInventory_mc start dragging when emptyBowl_mc is clicked, apply startDrag() there:

              '


              emptyBowl_mc.onPress = function() {
              ebVisible = false;
              emptyBowl_mc._visible=ebVisible;
              _root.inv_mc.emptyBowlInventory_mc._visible=true;

              _root.inv_mc.emptyBowlInventory_mc.stopDrag();


              }


              • 4. Re: movieclip becomes visible and attached to cursor
                learner102 Level 1

                Thank you, i see what your saying.  My problem was i did not realize to start my hidden inventory item at the same location as the non-hidden one, then proceed with the drag script.  I appreciate you opening my eyes .