Another Drag Question

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:


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=


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

Basically “trip” is just a variable.

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


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

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?

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.

remind me or i’ll forget!

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?