Skip to main content
September 8, 2009
Answered

events that delete functions

  • September 8, 2009
  • 1 reply
  • 941 views

Say I have a dragable object with something like

on(press){
    startDrag("object");
}
on(release){
    stopDrag();

}

How do I make it so that when the mouse button is released it makes it so the object can't be picked up any more (basically it removes the on(press) part)?

This topic has been closed for replies.
Correct answer kglad

remove your code from your button/movieclip and use:

btn.onPress=function(){

object.startDrag();

}

btn.onRelease=function(){

object.stopDrag();

}

then if you want to remove btn's onPress handler in its onRelease, use:

btn.onRelease=function(){

delete this.onPress

object.stopDrag();

}

or if you want to keep btn's onPress handler but disable the startDrag() only, use:

btn.onPress=function(){

if(!alreadyDragged){

alreadyDragged=true;

object.startDrag();

}

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
September 9, 2009

remove your code from your button/movieclip and use:

btn.onPress=function(){

object.startDrag();

}

btn.onRelease=function(){

object.stopDrag();

}

then if you want to remove btn's onPress handler in its onRelease, use:

btn.onRelease=function(){

delete this.onPress

object.stopDrag();

}

or if you want to keep btn's onPress handler but disable the startDrag() only, use:

btn.onPress=function(){

if(!alreadyDragged){

alreadyDragged=true;

object.startDrag();

}

}

September 9, 2009

Does that code go on the object or the frame?

Inspiring
September 9, 2009

Goes on the frame. You should stop using object code -- unless you need to publish to Flash 5 or earlier. Here is a good article about the issue:

http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent