# \[mx\] any way of storing the current position of an object

**URL:** <https://forum.kirupa.com/t/mx-any-way-of-storing-the-current-position-of-an-object/30166>\
**Category:** flash\
**Created:** [September 4, 2003, 5:04pm UTC](https://forum.kirupa.com/t/mx-any-way-of-storing-the-current-position-of-an-object/30166 "2003-09-04T17:04:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kdzines](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@kdzines](https://forum.kirupa.com/u/kdzines)\
**Post date:** [September 4, 2003, 5:04pm UTC](https://forum.kirupa.com/t/mx-any-way-of-storing-the-current-position-of-an-object/30166/1 "2003-09-04T17:04:07Z")

</div>

hey,

I’ve always wondered if there was a way to retrieve and store the current position of an object.

i am trying to develop a background slideshow using penners equations. but i get into trouble because you have to define the start position.

so let’s say you click button 1, and the object moves from x =0 to x = 200.

Now when i press button 2, i want the object to move from x = 200 to x = 400.

and if i then press button 4, i want it to move from x=200 to x=800 and so on.

So i need to go from the current position to any of the new positions.

i could do this simply using the normal inertia code.

```php

this.onEnterframe = function(){
if(change ==2){
if(_x!=400){
_x +=(400 - _x)/speed;
}
}

if(change==3){
if(_x!=600){
_x +=(600 - _x)/speed;
}
}

}

```

With something like this, the object will move both left and right and by different amounts depending on the button pressed.

I want to do this using penner’s eqs.

Any ideas,

kd

---

<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 4, 2003, 5:17pm UTC](https://forum.kirupa.com/t/mx-any-way-of-storing-the-current-position-of-an-object/30166/2 "2003-09-04T17:17:24Z")

</div>

um, to get the objects current x position, just type object.\_x

your code in AS:  
[AS]  
on(press){  
movie.\_x +=200;  
}  
[/AS]

---

<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 4, 2003, 5:24pm UTC](https://forum.kirupa.com/t/mx-any-way-of-storing-the-current-position-of-an-object/30166/3 "2003-09-04T17:24:40Z")

</div>

urh,

but that’s setting the \_x. i want to retrieve it based on what has happened before.

Am i missing something?

---

<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 4, 2003, 5:28pm UTC](https://forum.kirupa.com/t/mx-any-way-of-storing-the-current-position-of-an-object/30166/4 "2003-09-04T17:28:17Z")

</div>

you can set it or retrieve it. if you just want to store the value in a variable, go

[AS]  
xvalue = movie.\_x;  
[/AS]

I’m not sure i totally understand what you are asking

---

<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 4, 2003, 5:44pm UTC](https://forum.kirupa.com/t/mx-any-way-of-storing-the-current-position-of-an-object/30166/5 "2003-09-04T17:44:54Z")

</div>

ok so an example:

```php

dNum = 20;
tNum = 0;
endNum = -730;
//////////////////////////////

var start = strip._x;
var end = strip._x+_root.endNum;
var duration = _root.dNum;
var t = _root.tNum;
_root.Change = 0;
this.onEnterFrame = function() {
	if (_root.Change == 2) {
        if (t<=duration) {
                strip._x = Math.EaseInOutQuint(t, start, end, duration);
				t++;

        }
	}
	if (_root.Change == 3) {
        if (t<=duration) {
                strip._x = Math.EaseInOutQuint(t, start, end, duration);
				t++;

        }
	}
};
butt2.onPress = function() {
	_root.Change = 2;
	t=0;
};

butt3.onPress = function() {
	_root.Change = 3;
	t=0;
};

//strip is the instance name of the object i want to move

```

Crude example but:  
Say i press butt2 - movie moves from x=0 to x=-730;

now say i press butt3 - i want the movie to move anothe -730 from its current position which is X=-730;

But this doesn’t happen. Instead when i press butt3, strip starts again from x=0, and moves -730 pixels.

Can you see what i mean now? I want to constantly check where the current x position is, and store that figure as a variable.

Thanks, hope you understand my ramblings!

kd

---

<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 4, 2003, 5:51pm UTC](https://forum.kirupa.com/t/mx-any-way-of-storing-the-current-position-of-an-object/30166/6 "2003-09-04T17:51:08Z")

</div>

try this

[AS]  
onClipEvent(enterFrame){  
stripXPos = strip.\_x;  
}  
[/AS]

this will constantly update stipXPos to whatever the xvalue of strip is. See if this help at all.

---

<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 4, 2003, 6:05pm UTC](https://forum.kirupa.com/t/mx-any-way-of-storing-the-current-position-of-an-object/30166/7 "2003-09-04T18:05:30Z")

</div>

hey,

That’s exactly what i was just thinking. But i still can’t get it to work.

Here is the new code:

```auto

dNum = 20;
tNum = 0;
endNum = -730;
//////////////////////////////

var start = stripXPos;
var end = stripXPos+_root.endNum;
var duration = _root.dNum;
var t = _root.tNum;
_root.Change = 0;
this.onEnterFrame = function() {
	stripXPos = strip._x;
	if (_root.Change == 2) {
        if (t<=duration) {
                strip._x = Math.EaseInOutQuint(t, start, end, duration);
				t++;

        }
	}
	if (_root.Change == 3) {
        if (t<=duration) {
                strip._x = Math.EaseInOutQuint(t, start, end, duration);
				t++;

        }
	}
};
butt2.onPress = function() {
	_root.Change = 2;
	t=0;
};

butt3.onPress = function() {
	_root.Change = 3;
	t=0;
};

```

I totally understand now that you need something in side the enterframe so it can constantly check the x position. But can’t figure out how to integrate it.

Any ideas? maybe you can see something wrong in the code,

Thanks for all the help so far

kd

---

<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 4, 2003, 6:12pm UTC](https://forum.kirupa.com/t/mx-any-way-of-storing-the-current-position-of-an-object/30166/8 "2003-09-04T18:12:16Z")

</div>

you never update the value of start. You are passing it as a parameter to some function but I assume you need to update it first.
