How I can center tow movieClip after an hitTest, because I have a problème with my code ?
Hello,
I have an other problem.
I made fort the test a simple animation. I have tow movieClips inside (Dot1 and Dot2) a MovieClip from the library called (LineMovieClip). I trace a line between the tow "Dot" and I can move the "Dot2" with startDrag. I have a red square on stage, and I made an hitTest. When that hitTest is "true" I'm trying to center the "Dot2" with the "redSquare", but I have a problème because the .x and .y aren't in the same "stage" (on on the principal the "square", and on the "LineMovieClip")
My code is :
"
let root = this;
var MakeTheLine = new createjs.Shape();
this.addChild(MakeTheLine);
let Line_mc = new lib.LineMovieClip();
this.addChild(Line_mc);
MakeTheLine.x = Line_mc.x = 100;
MakeTheLine.y = Line_mc.y = 100;
function MakeTheLineF() {
MakeTheLine.graphics.clear();
console.log(MakeTheLine.graphics)
MakeTheLine.graphics.setStrokeStyle(3);
MakeTheLine.graphics.beginStroke("#0000ff");
MakeTheLine.graphics.moveTo(Line_mc.Dot1.x, Line_mc.Dot1.y);
MakeTheLine.graphics.lineTo(Line_mc.Dot2.x, Line_mc.Dot2.y);
}
Line_mc.Dot2.on("mousedown", onMouseDownDot2.bind(this));
Line_mc.Dot2.on("pressmove", onMouseMoveDot2.bind(this));
Line_mc.Dot2.on("pressup", onMouseUpDot2.bind(this));
function onMouseDownDot2 (evt){
var item = Line_mc.Dot2;
item.offset = {x:0, y:0};
var pt = item.parent.globalToLocal(evt.stageX, evt.stageY);
item.offset.x = pt.x - item.x;
item.offset.y = pt.y - item.y;
item.drag = true
};
function onMouseMoveDot2(evt){
var item = Line_mc.Dot2;
if (item.drag){
var pt = item.parent.globalToLocal(evt.stageX , evt.stageY);
item.x = pt.x - item.offset.x;
item.y = pt.y - item.offset.y;
}
MakeTheLineF();
};
function onMouseUpDot2(evt){
var pt = Line_mc.localToLocal(Line_mc.Dot2.x,
Line_mc.Dot2.y, root.RedSquare_mc);
if(root.RedSquare_mc.hitTest(pt.x, pt.y)){
console.log("Hit");
Line_mc.Dot2.x = root.RedSquare_mc;
Line_mc.Dot2.y = root.RedSquare_mc;
}
}
//
MakeTheLineF();
"
==> the problème is here :
"
Line_mc.Dot2.x = root.RedSquare_mc;
Line_mc.Dot2.y = root.RedSquare_mc;
"
Can you help me.
Thanks very much.
Romain
