Storing initial position of mc

Is there a way of storing somehow the initia position of a mc, so that if it is dragged when you release the button it goes bact to its initial position??

I tryed to put something like
onClipEvent (load){
this._x = posicionx;
this._y = posiciony;

and afte call to this variables.But is doesn’t work.

Try this its a small example of an experiment I was trying

the button goes back to the original x and y

this is exactly what i was trying to do. Dirung the time you answered i came up with this, similar but not the same (for sure your code is much better) . This code i came up with doesn’t work propperly, because the mc goes bac to the point, but not always exactly where it should. Any idea Why??? (well, as you will see it does soething else when reaching a point, but this works fine)

onClipEvent (enterFrame){
function coger(){
startDrag (this,true);
if (this.hitTest (_root.pantalla)){
trace (“hola”);
this._alpha = 50;
function soltar(){
stopDrag ();
[/COLOR] [COLOR=indigo]//this ifs should put it back where it belonged!! right??[/COLOR][COLOR=blue]
if (this._x >247) this._x-=10;
if (this._x <247) this._x+=10;
if (this._y>36) this._y -=10;
if (this._y<36) this._y +=10;
this.onPress = function(){
this.onEnterFrame = coger;
this.onRelease = function(){
this.onEnterFrame = soltar;


Anyway, your code is perfect. But i still wonder if there is a way to put the initial position “by default”, i mean, the position of the mc when it loads, so you don’t have to put the x and y coordinates in each mc.

EDIT: is it because i’m not telling the position is in the _root???

Actually I changed the fla because the code should have been more neater - the initial x and y should have been in load not enter frame - there’s no need to keep telling it every frame what the old x and y were

Also don’t define functions in enterFrame - you only need to do it once. You can do it in on load, or in the main time line in a layer called functions if you like. Just make sure you define it before calling it and use the right target path - there is a thread here about functions.

Well, i see what you mean. But now i have a question: I don’t really understand [COLOR=darkblue]if (_root.go1)[/COLOR] :-\

i cannot find go1… (maybe i should sleep more :stuck_out_tongue: )

Check the actions for the button inside the mc. I haven’t set the initial value of go1 anywhere, I just declare it and set at the same time in the button.

On release _root.go1 becomes true.

And I thought you had set your functions in enterFrame - but you hadn’t - my bad - but it’s good advice anyway.

oh… i see…
i didn’t thought there was a button. I thought there was only a mc. i should work the same right???
oh, and which is the difference in using this._x and _x inside the actions of a mc? all actions are refered to it, aren’t they?

EDIT: And i don’t understand the coding inside the button. I’m a bit slow today, sorry … :frowning:

Here is my fla…
corect _x ,wrong _y…

Essentially, in MX you can use this._x or _x, this referrs to this time line of this mc or button, etc.

Try this:

:o :o :o :o :o :o

and why is that???

now i feel pretty stupid. and sure you are beginning to de bored of me!!!

:o :o :o :o :o :o :o

even more stupid now i’ve tryed this…
look at the second a thirth discs. They go the same _y!!!

i guess i need a little bit o theory about this thing here.:o

I put my code on your fla. Try this


thanks again!

Well, now i’ve checked the fla. I see the code, but don’t get how it works inside the button.

on (press) {
startDrag(this, true);
_root.go1 = false;
on (release) {
_root.go1 = true;

what does _root.go1 = false; line do???

And i wonder if someone has an explanation for what was happening in the previous fla. The one where the mc went back to an incorrect _y :q: :q: :q:

It seemed to be that the mcs were looking at the same variables, because once you dragged one mc - the other’s were disabled - and if do dragged the 2nd it would go to the x and y of the 1st.

You also had the functions in onEnterFrame which you didn’t need - and I think the onPress and onRelease would have been better on a button.

But anyway when the button (so that means also the mc) is dragged ie on (press) _root.go1 becomes false. That means that

if (_root.go1) {
_x += (old_x-_x)/speed; // this line won’t run
_y += (old_y-_y)/speed; // nor will this

because the if statement checks if _root.go1 is true, so the disk won’t return to their original position, as _root.go1 is false.

But when you release, on (release), then _root.go1 becomes true, allowing the two lines I commented above to run, in other words, the disk will return back to it’s original position.

i understand almost everything…:*( :frowning:

what’s go1 ??? i can’t find it

(i’m beggining to fell embarased… :*( )

Give me a sec - I’ll comment your fla and repost it…