Sunday, April 4, 2010

events that delete functions

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)?

events that delete functions

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

}

}

events that delete functions

Does that code go on the object or the frame?

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

Once a function has been deleted in this way, is it possible to undelete it? Say I want to make a reset button that makes all the objects dragable again, is that possible? I didn't notice anything about this on the linked page.

if you use the last code snippet i suggested, you can assign alreadyDragged to false to reset/re-allow the piece to be dragged again.

I can't seem to get that last bit of code to work. It wont let me pick up and drag the object. Also, what if there are multiple objects?

Edit: oh, wait, I just had to change object.startDrag(); to startDrag(this); to make it work. Also, I guess for multiple objects I just need to change the name of alreadyDragged don't I. OK, I think this is working the way I want it now, thanks for all the help.

you're welcome.

  • red lipstick
  • No comments:

    Post a Comment