Dragging

Hey, i’m trying to get a box to drag (it’s a button within a movieclip), but my code just ends up dragging the whole stage, and i don’t know what i’m doing wrong. :-\

The code is:

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

I tried putting the name of the button instance in the “”, but that just makes the code do nothing.

:q: :cyclops: :q:

Hi there,

i don’t understand what you mean by dragging the whole stage but I will explain how to get the object to drag.

Firstly you can drag only a movieclip so if u want to drag a button, create a button, then create a movieclip and from the library
(Ctrl + L) drag the button onto the movieclip. then go to the main movie time line and drag the movie clip from the library onto the stage and give it an instance name in the instance dialogue box. then right click on the mc and click on the edit. then right click on the button and click on actions and give the following actions
on (press) {
startDrag ("/instance name of the movieclip");
}
on (release) {
stopDrag ();
}

This should work

Try startDrag(this);

pom :asian:

You need to specify what you want to drag. So…

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

<b>should become</b>

on (press) {
startDrag (“yourMC”);
}
on (release) {
stopDrag ();
}

where yourMC = the movie clip you want to be dragged.

hey,
i tried converting the thing to a movieclip, and output says this:

Symbol=news, Layer=dragger, Frame=1: Line 1: Mouse events are permitted only for button instances
on (press) {

Symbol=news, Layer=dragger, Frame=1: Line 4: Mouse events are permitted only for button instances
on (release) {

So i converted it to a button again, and left “” blank, and it ends up dragging everything. What i mean about the ‘whole stage’ is that i have the button on top of a graphic (the bg), and it drags the background as well as the thing it’s supposed to be dragging.

Here’s the code i put on the button, with the button instance named:

on (press) {
startDrag (“dragger”);
}
on (release) {
stopDrag ();
}

…dragger being the button instance. I tried that before i posted for the first time, nothing’s working… :frowning: Basically, the only way i get anything to drag, is if i have it as a button, and leave “” blank. :frowning:

If you want to drag the button, just type the instance name of your button between " "

There are no instance names for buttons in Flash 5, lost :stuck_out_tongue:
Did you try startDrag (this) ?

pom :asian:

yea, i tried ‘this’, it doesn’t do anything…

I meant by instance name, i named the button ‘dragger’, then i put it on the stage, so that would be an instance of ‘dragger’.

lostinbeta, i’ve tried to explain that i did type in the name of the button between “”, but nothing will drag. :frowning:

Well I created a button named dragger. Then in the instance name I typed “dragger” (without quotes). Then I applied the exact code you added…


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

Everything worked great. I even added more things into the movie just to see if everything would drag, nope, just the button was being drug around.

I would post the .fla, but it is Flash MX, so Flash 5 won’t be able to read it. If you use MX, let me know, I will post the .fla here for you in a .zip file.

There are no instance names for buttons!! (Haven’t I said that already?:P)
If you want to drag anything, you have to target a movie clip. In this case, ‘this’. It works, I’ve just tested it (if you a button inside a movie clip, of course).

pom :asian:

There are instance names for buttons. I just tried it and it worked. I used it with buttons all the time.

Attached is a picture of the buton properties in Flash MX.

If there isn’t in Flash 5, sorry, I never learned deeply about Flash 5, I just figured they wouldn’t have changed that.

My apologies.

mmm

yea, i use flash 5, and there aren’t any instance names for buttons… grrr… i guess it only works on MX?! sigh.

the reason why lostinbeta’s solution doesn’t work in flash 5 is cuz there aren’t any instance names for buttons.

I’ll try pom’s idea now. :stuck_out_tongue:

No nee to apologize :slight_smile: Actually, instance names for buttons are new, and totally useless now that you can give movie clips button handlers…

pom :asian:

*Originally posted by natalia *
**hey,
i tried converting the thing to a movieclip, and output says this:

Symbol=news, Layer=dragger, Frame=1: Line 1: Mouse events are permitted only for button instances
on (press) {

Symbol=news, Layer=dragger, Frame=1: Line 4: Mouse events are permitted only for button instances
on (release) {

So i converted it to a button again, and left “” blank, and it ends up dragging everything. **
OK, there is the problem. Let take this back from the beginning:
You have a graphic, you turn it into a button, and give it the code

on (press) {startDrag (this);}

For the moment, this refers to the _root (the parent of the button) so it won’t work.
Now turn your button into a movie clip (F8) and that’s it! :slight_smile:

pom :asian:

okay, now i’m hopelessly confused. all i wanted to do was to make this little box drag…

i can’t do button instances on flash 5.
if i make it into a movieclip, i can’t use the ‘on’ code in the actionscript box because i need an ‘onclip’ code. With the ‘onclip’, it doesn’t drag.

k pom, i posted the above right after you posted the new solution… i’ll try that =)

see attachment.:slight_smile: