Skip to main content
marliton
Braniac
September 1, 2017
Answered

Identify an instance by the name

  • September 1, 2017
  • 1 reply
  • 2297 views

Hi.

In an HTML5 canvas document, I'm trying to identify an element using the name when I click it. In AS3 the name property (evt.target.name) is the same instance name. With EaselJS seems to be different. I can use the name property for assign a name but I can't recover the name with evt.target.name. How can I do it?

this.circle.name = "orange";

this.circle.addEventListener("click", test.bind(this));

function test(evt) {

     console.log(evt.target.name); //This doesn't works. Return null.

}

Thanks.

This topic has been closed for replies.
Correct answer Colin Holgate

You are clicking on a Shape, and that's the target. The movieCLip is the shape's parent. This works:

this.circle.name = "orange";

this.circle.addEventListener("click", test.bind(this));

function test(evt) {

     alert(evt.target.parent.name); //This doesn't works. Return null.

}

1 reply

Colin Holgate
Colin HolgateCorrect answer
Inspiring
September 1, 2017

You are clicking on a Shape, and that's the target. The movieCLip is the shape's parent. This works:

this.circle.name = "orange";

this.circle.addEventListener("click", test.bind(this));

function test(evt) {

     alert(evt.target.parent.name); //This doesn't works. Return null.

}

marliton
marlitonAuthor
Braniac
September 1, 2017

Works perfectly! Thanks a lot.

Are you going to AdobeMax? I need to meet to my JS hero! :-)

Marlon Ceballos
kglad
Braniac
May 3, 2024

@ClayUUIDI'd like to be able to target movieclip w/o needing an instance name, but your link to "Re: HTML Canvas instance names - Good tricks to getting them?" does not work any more. Seems like Adobe rebuilt the forums at some point. I did try searching on that post title, but nothing came up.


how do you want to reference it?