Skip to main content
Inspiring
July 28, 2020
Answered

Open MovieClip over mouse position

  • July 28, 2020
  • 1 reply
  • 299 views

Hello, guys! The task. I have movieclip panel_PA_anim, which has eventListener. I would like to open another MC and put it over mouse. How should I adjust my code to fix it?

 

this.panel_PA_anim.addEventListener("click", (e) => {

let l = this.globalToLocal(stage.mouseX, stage.mouseY);

Object(this.parent).incorrect.x = l.x;
Object(this.parent).incorrect.y = l.y;

Object(this.parent).incorrect.visible = true;
let a = () => {
Object(this.parent).incorrect.visible = false
}
setTimeout((a), 700);

});

 

 

Thank you in advance!

    This topic has been closed for replies.
    Correct answer Igor Sulim

    Hi, mate!

    I've found that this code works, but clips should be at the same stage (in the same coordinate system).

     

    this.incorrect_PA.visible = false;
    
    this.panel_PA_anim.addEventListener("click", (e) => {
    	
    	let l = this.globalToLocal(stage.mouseX, stage.mouseY);
    	
    	this.incorrect_PA.x = l.x;
    	this.incorrect_PA.y = l.y
    	
    	this.incorrect_PA.visible = true;
    	let a = () => {
    		this.incorrect_PA.visible = false
    	}
    	setTimeout((a), 700);
    	
    });

    1 reply

    kglad
    Community Expert
    Community Expert
    July 29, 2020

    if that code actually compiles, you need to explain what you're doing.  if that code was copied from somewhere unrelated to animate, and incorrect and panel_PA_anim are both children of the same movieclip that contains your code, use:

     

    this.panel_PA_anim.addEventListener("click", f.bind(this));

    var to;

    function f(){

    var l = this.globalToLocal(stage.mouseX, stage.mouseY);

    this.incorrect.x = l.x;
    this.incorrect.y = l.y;

    this.incorrect.visible = true;
    clearTimeout(to);
    to=setTimeout(a, 700, this);

    };

    function a(tl){

    tl.incorrect.visible = false

    }

    Igor SulimAuthorCorrect answer
    Inspiring
    July 29, 2020

    Hi, mate!

    I've found that this code works, but clips should be at the same stage (in the same coordinate system).

     

    this.incorrect_PA.visible = false;
    
    this.panel_PA_anim.addEventListener("click", (e) => {
    	
    	let l = this.globalToLocal(stage.mouseX, stage.mouseY);
    	
    	this.incorrect_PA.x = l.x;
    	this.incorrect_PA.y = l.y
    	
    	this.incorrect_PA.visible = true;
    	let a = () => {
    		this.incorrect_PA.visible = false
    	}
    	setTimeout((a), 700);
    	
    });