all groups > flash actionscript > september 2004 >
You're in the

flash actionscript

group:

finding the current location of a movie clip



Re: Tryingto not to use the load movieClip event. (_seb_)
9/7/2004 10:31:50 PM
flash actionscript: interested in what?
there is no thread


[quoted text, click to view]

finding the current location of a movie clip Mrs. Nottingham
9/7/2004 10:42:30 PM
Does anyone know how to detect the current location of a movie clip? I have
several different ways a movieClip can animate depending on where it came to
rest at the end of the last motion. My problem is that the motion keeps
starting at the x,y location of where it is in the beginning of the movieClip
instead of where it last came to rest. Thanks.

onClipEvent (load) {
//These are the starting points.

gox = this._x;//This is where it screws up and sets gox to the starting point
of the movie clip location.
goy = this._y;
//These are where you want it to stop moving. (resting point)
targetx = 10;
targety = 300;

//This controls the speed.
smooth = .1;
}
onClipEvent (enterFrame) {
// rotate right or left
gox += (targetx-gox)*smooth;
goy += (targety-goy)*smooth;
_x = gox;
_y = goy;

}

Re: finding the current location of a movie clip rlc5611
9/7/2004 11:14:12 PM
Since this is in a load event, whatever the MC knew about itself before would
be forgotten when it is reloaded. One thing you could do would be to have the
MC "save" its last position external to itself like _parent.myx = _x and
_parent.myy = _y in the enterFrame event or, even better, in an unload event if
you can.

Then for your onLoad event add a short check like

if(_parent.myx <> undefined) {
gox = _parent.myx;
goy = _parent.myy;
} else {
gox = this._x;
goy = this._y;
}

or something along those lines.
Re: finding the current location of a movie clip Mrs. Nottingham
9/7/2004 11:24:35 PM
Thanks a lot. I'm really a beginner here, and I'm not sure how to apply what
you just said. Is there any way you could write that beginning part out for me?
I understand if you can't. I'm a Director/Lingo person and I'm feeling like my
hands are tied with ActionScript.
Re: finding the current location of a movie clip Mrs. Nottingham
9/7/2004 11:35:46 PM
I've incorporated the changes how I thought you meant, and it does work better.
However, I see a flash of the mc starting back at the old start-point before it
readjusts and works properly. Is this because I haven't unloaded it? How do I
do that? Thanks so much.

My new code:

onClipEvent (load) {
//These are the starting points.
if (_parent.myx<>undefined) {
gox = _parent.myx;
goy = _parent.myy;
} else {
gox = this._x;
goy = this._y;
}
//These are where you want it to stop moving. (resting point)
targetx = 110;
targety = 100;
//This controls the speed.
smooth = .1;
}
onClipEvent (enterFrame) {
// rotate right or left
gox += (targetx-gox)*smooth;
goy += (targety-goy)*smooth;
_x = gox;
_y = goy;
_parent.myx = _x;
_parent.myy = _y;
}

Tryingto not to use the load movieClip event. Mrs. Nottingham
9/8/2004 2:06:08 AM
Re: Tryingto not to use the load movieClip event. Mrs. Nottingham
9/8/2004 2:44:05 AM
Sorry about that. I changed the Message Title when I replied. I didn't realize
that destroyed the thread. Here's a copy of the thread:

Does anyone know how to detect the current location of a movie clip? I have
several different ways a movieClip can animate depending on where it came to
rest at the end of the last motion. My problem is that the motion keeps
starting at the x,y location of where it is in the beginning of the movieClip
instead of where it last came to rest. Thanks.

onClipEvent (load) {
//These are the starting points.

gox = this._x;//This is where it screws up and sets gox to the starting point
of the movie clip location.
goy = this._y;
//These are where you want it to stop moving. (resting point)
targetx = 10;
targety = 300;

//This controls the speed.
smooth = .1;
}
onClipEvent (enterFrame) {
// rotate right or left
gox += (targetx-gox)*smooth;
goy += (targety-goy)*smooth;
_x = gox;
_y = goy;

}

------------------------------------




rlc5611
Senior Member

Posts: 1058
Joined: 03/02/2004
09/07/2004 04:14:12 PM


Since this is in a load event, whatever the MC knew about itself before would
be forgotten when it is reloaded. One thing you could do would be to have the
MC "save" its last position external to itself like _parent.myx = _x and
_parent.myy = _y in the enterFrame event or, even better, in an unload event if
you can.

Then for your onLoad event add a short check like

if(_parent.myx <> undefined) {
gox = _parent.myx;
goy = _parent.myy;
} else {
gox = this._x;
goy = this._y;
}

or something along those lines.

------------------------------------------




Mrs. Nottingham
Junior Member

Posts: 13
Joined: 05/25/2004
09/07/2004 04:24:34 PM


Thanks a lot. I'm really a beginner here, and I'm not sure how to apply what
you just said. Is there any way you could write that beginning part out for me?
I understand if you can't. I'm a Director/Lingo person and I'm feeling like my
hands are tied with ActionScript.

-------------------------------------------



Mrs. Nottingham
Junior Member

Posts: 13
Joined: 05/25/2004
09/07/2004 04:35:45 PM


I've incorporated the changes how I thought you meant, and it does work
better. However, I see a flash of the mc starting back at the old start-point
before it readjusts and works properly. Is this because I haven't unloaded it?
How do I do that? Thanks so much.

My new code:

onClipEvent (load) {
//These are the starting points.
if (_parent.myx<>undefined) {
gox = _parent.myx;
goy = _parent.myy;
} else {
gox = this._x;
goy = this._y;
}
//These are where you want it to stop moving. (resting point)
targetx = 110;
targety = 100;
//This controls the speed.
smooth = .1;
}
onClipEvent (enterFrame) {
// rotate right or left
gox += (targetx-gox)*smooth;
goy += (targety-goy)*smooth;
_x = gox;
_y = goy;
_parent.myx = _x;
_parent.myy = _y;
}





AddThis Social Bookmark Button