• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How I can center tow movieClip after an hitTest, because I have a problème with my code ?

Community Beginner ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

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

Views

579

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 16, 2023 May 16, 2023

you're welcome.

Votes

Translate

Translate
Community Expert ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

you should spend a few minutes learning how to debug your own code.  then come here for more difficult problems.

 

Lesson 1: https://youtu.be/bG05_am-fQI

Lesson 2: https://youtu.be/H9e9toftvdM

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

Thanks, your right...

I will see the video.

But I am a simple biology teacher who try to make application for my student, I'm a beginner in HTML5, I was OK with AS2 and AS3, but that hard for me to find all the differences of psychology...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

i understand.  we were all beginners at one time.

 

the most important thing to learn with any coding system is how to debug your errors because you're going to make errors.  if you don't know how to debug your errors you waste a lot of time.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

I will try to find my probem with your video, and if don't arrived to find a solution I will call the community to help me again.

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

sounds good.

 

(copy and paste any non-default error messages you see.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

I saw your video, and that not a problème og bug, I haven't error message.

My problem is because I don't know how I can have the .x and .y of coordonate between my stage and my Dot2 who is inside a movieClip.

I sand you my image of screenshot

hitTest.jpg

I write this

"

Line_mc.Dot2.y = root.RedSquare_mc.y;
Line_mc.Dot2.x = root.RedSquare_mc.x;

"

fin this

"

Line_mc.Dot2.y = root.RedSquare_mc.y - Line_mc.y;
Line_mc.Dot2.x = root.RedSquare_mc.x - Line_mc.x;

"

that work, but may be we can do better...

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

what's wrong with

 

Line_mc.Dot2.y = root.RedSquare_mc.y - Line_mc.y;
Line_mc.Dot2.x = root.RedSquare_mc.x - Line_mc.x;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 16, 2023 May 16, 2023

Copy link to clipboard

Copied

Hello, nothing that work very well.

Thanks for everything

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 16, 2023 May 16, 2023

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines