Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : Centering on center of drop zone


BenFranklin
5/28/2004 8:50:59 PM
I have a very simple operation that I can't get to work right and can't find a
reliable source for how to do it.

I want to drag one movie clip onto another, establish via hitTest that it's in
the right zone, and then have the top movie clip center itself over the center
of the bottom movie clip. I copied this code from a matching game where it
works...

this._x = _parent.dropZone._x;
this._y = _parent.dropZone._y;

where "dropZone" is the bottom movie clip. But on mine, instead of centering
the top clip it aligns its upper left corner with that of the bottom clip. Both
clips have their registration points in the center, at least it looks like they
do. What am I doing wrong? Thanks.
Drapple
5/29/2004 12:27:38 AM
Its the same as an exersize I have just done. The code looks correct so I bet
the movie clips aren't centered.

Here is the full code from the exersize:



onClipEvent (load) {
origX = this._x;
origY = this._y;
}

onClipEvent (mouseDown) {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
this.startDrag();
}
}
onClipEvent (mouseUp) {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
this.stopDrag();

// see if the dropZone conatins the center of this mc
if (_parent.dropZone1.hitTest(this._x,this._y,true)) {

// center it on the drop zone
this._x = _parent.dropZone1._x;
this._y = _parent.dropZone1._y;
} else {

// return it to its original location
this._x = origX;
this._y = origY;
}
}
}
BenFranklin
6/1/2004 5:15:58 PM
Thanks, that was the one I was using too, but it wasn't working. I started over
from scratch and the X and Y seem to work to center it now. I don't know if
there was some glitch in the other clips that was failing to record a new
registration point after it may have initially been set to the corner, or what.

Now I have a whole nother centering issue, though, that's even more bizarre. I
guess I'll ask it in a different thread. Thanks for your help.
AddThis Social Bookmark Button