# Another Drag Question

**URL:** <https://forum.kirupa.com/t/another-drag-question/18048>\
**Category:** flash\
**Created:** [April 12, 2003, 5:54pm UTC](https://forum.kirupa.com/t/another-drag-question/18048 "2003-04-12T17:54:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RageW0lf](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@RageW0lf](https://forum.kirupa.com/u/RageW0lf)\
**Post date:** [April 12, 2003, 5:54pm UTC](https://forum.kirupa.com/t/another-drag-question/18048/1 "2003-04-12T17:54:45Z")

</div>

Ok I have another drag question. I am getting sick of asking questions so frustrating at times! if only I was a guru like Pom :asian:

Ok I have been playing with dragging. I wanted to have a picture that you could load in dynamically and drag around, and when you released it would go back to its original position.  
If anybody knows a tutorial of this PLEASE post it and out me out of my misery.

Anyway, as I am newbie, I though it may be best to make it do that when you pressed a “reset” button to start with because I think I will have to mess about with functions and things otherwise.

I can drag it about, and have created a the “reset” which sends the pic back to its start position 0,0.

The code in frame one to load it in is:

```auto

loadMovie("photo.jpg", "location");
location._x = 0;
location._y = 0;
_root.onMouseDown = function() {
    startDrag("location", false, 0, 0, 500, 500);
};
_root.onMouseUp = function() {
    stopDrag();
};

```

“location” is a movie clip symbol on the main timeline.

My button has the following code=

```auto

on (release) {
    tellTarget ("location") {
        trip = 1;
    }
}

```

Basically “trip” is just a variable.

Attached to this movie clip instance “location” I have the following code

```auto

onClipEvent (load) {
    _x = 0;
    _y = 0;
    rateOfChange = 5;
}
onClipEvent (enterFrame) {
    if (trip == 1 && _root.location._x>0) {
        _root.location._x -= rateOfChange;
    }
    if (trip == 1 && _root.location._y>0) {
        _root.location._y -= rateOfChange;
    }
}
onClipEvent (enterFrame) {
    if (_root.location._x == 0 && _root.location_y == 0) {
        _root.location.trip = 0;
    }
}

```

The problem is this - it DOESN’T set trip to 0.  
After its reset and you drag it out again it keeps trying to go back to 0 before you even press the button.  
The irony of this is that this is kind of what I wanted to do originally…

How do I stop it from doing this? (how do I Unset trip = 1?)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 12, 2003, 8:11pm UTC](https://forum.kirupa.com/t/another-drag-question/18048/2 "2003-04-12T20:11:44Z")

</div>

this [AS] tellTarget (“location”) {  
trip = 1;  
[/AS] is obsolete,  
replace by \_root.location.trip = 1;

then, replace  
[AS] loadMovie(“photo.jpg”, “location”);  
location.\_x = 0;  
location.\_y = 0;  
\_root.onMouseDown = function() {  
startDrag(“location”, false, 0, 0, 500, 500);  
};  
\_root.onMouseUp = function() {  
stopDrag();  
};  
[/AS] by

[AS] loadMovie(“photo.jpg”, “location”);  
X=location.\_x ; //=0  
Y=location.\_y; //=0  
\_root.onMouseDown = function() {  
startDrag(“location”, false, 0, 0, 500, 500);  
};  
\_root.onMouseUp = function() {  
stopDrag();  
\_root.location.\_x = X;  
\_root.location.\_y=Y; //or add easing here…  
};  
[/AS] whixch is all you need…

also, it’d be better not to use \_root.onMouseEvent,  
but to detect before the start drag if hitTest location/mouse = true, and drag only then, and it’s not easy to see if you got all the paths right without seeing where this code is (all over the place…) Flash MX: all this could be grouped in function(s) in frame 1 of \_root…  
want a fla?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 13, 2003, 10:35am UTC](https://forum.kirupa.com/t/another-drag-question/18048/3 "2003-04-13T10:35:14Z")

</div>

Sure if you want to donate a fla…  
Thanks for your reply also.

You are right though, the script is very messy indeed!

I havn’t learnt to use functions yet because for making a simple site you just don’t need to know it.

Actionscript is something I am now turning my attentions to, so hopefully I will have a much better idea in a few months.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 13, 2003, 7:06pm UTC](https://forum.kirupa.com/t/another-drag-question/18048/4 "2003-04-13T19:06:54Z")

</div>

remind me or i’ll forget!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 14, 2003, 5:03pm UTC](https://forum.kirupa.com/t/another-drag-question/18048/5 "2003-04-14T17:03:39Z")

</div>

Also, how do I ease it using actionscript? - I noticed you put that in a note there & I know it can be done.

Also I want it to move diagonally also - currently say it is dragged to +5 y and +300x it will level up y then just go straight - how could I make it go diagonal until its at its start place?  
I was thinking about it and you could divide each coordinate by say 10 then each frame make it move (in this case) -30x, -0.5y - would this be thinking along the right lines to make it do this?
