# Storing initial position of mc

**URL:** https://forum.kirupa.com/t/storing-initial-position-of-mc/6075
**Category:** Uncategorized
**Created:** [September 28, 2002, 7:05pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075 "2002-09-28T19:05:26Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![fadingblack](https://avatars.discourse-cdn.com/v4/letter/f/48db29/32.png) [@fadingblack](https://forum.kirupa.com/u/fadingblack)
#### Post date: [September 28, 2002, 7:05pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/1 "2002-09-28T19:05:26Z")

</div>

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  
[COLOR=blue]  
onClipEvent (load){  
this.\_x = posicionx;  
this.\_y = posiciony;  
}[/COLOR]

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

---

<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: [September 28, 2002, 7:17pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/2 "2002-09-28T19:17:13Z")

</div>

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

the button goes back to the original x and y

---

<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: [September 28, 2002, 7:32pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/3 "2002-09-28T19:32:08Z")

</div>

thanks!  
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)

[COLOR=blue]  
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;  
}

}

[/COLOR]  
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???

---

<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: [September 28, 2002, 7:45pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/4 "2002-09-28T19:45:57Z")

</div>

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

---

<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: [September 28, 2002, 7:48pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/5 "2002-09-28T19:48:44Z")

</div>

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.

---

<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: [September 28, 2002, 7:57pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/6 "2002-09-28T19:57:44Z")

</div>

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

---

<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: [September 28, 2002, 8:08pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/7 "2002-09-28T20:08:56Z")

</div>

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.

---

<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: [September 28, 2002, 8:09pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/8 "2002-09-28T20:09:46Z")

</div>

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

---

<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: [September 28, 2002, 8:13pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/9 "2002-09-28T20:13:27Z")

</div>

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 … ☹

---

<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: [September 28, 2002, 8:27pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/10 "2002-09-28T20:27:04Z")

</div>

Here is my fla…  
corect \_x ,wrong \_y…

---

<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: [September 28, 2002, 8:27pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/11 "2002-09-28T20:27:44Z")

</div>

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

---

<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: [September 28, 2002, 8:47pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/12 "2002-09-28T20:47:41Z")

</div>

Try this:

---

<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: [September 28, 2002, 9:28pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/13 "2002-09-28T21:28:00Z")

</div>

: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!!!

---

<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: [September 28, 2002, 9:32pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/14 "2002-09-28T21:32:42Z")

</div>

: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

---

<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: [September 29, 2002, 1:49am UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/15 "2002-09-29T01:49:16Z")

</div>

I put my code on your fla. Try this

---

<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: [September 30, 2002, 10:37pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/16 "2002-09-30T22:37:52Z")

</div>

HELLO!!

---

<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: [September 30, 2002, 10:42pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/17 "2002-09-30T22:42:32Z")

</div>

HELLO!!  
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) {  
stopDrag();  
\_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:

---

<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: [September 30, 2002, 11:00pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/18 "2002-09-30T23:00:37Z")

</div>

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.

---

<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: [September 30, 2002, 11:12pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/19 "2002-09-30T23:12:33Z")

</div>

i understand almost everything…:\*( ☹

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

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

---

<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: [September 30, 2002, 11:17pm UTC](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075/20 "2002-09-30T23:17:51Z")

</div>

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

[Next page](https://forum.kirupa.com/t/storing-initial-position-of-mc/6075.md?page=2)
