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

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.


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

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

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

urh,

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

Am i missing something?

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

ok so an example:


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

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.

hey,

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

Here is the new code:


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

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.