Skip to main content
June 14, 2011
Answered

movieclip becomes visible and attached to cursor

  • June 14, 2011
  • 1 reply
  • 385 views

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.

This topic has been closed for replies.
Correct answer kglad

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();


}


1 reply

kglad
Community Expert
Community Expert
June 14, 2011

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();

June 14, 2011

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.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 14, 2011

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();


}