Skip to main content
marliton
Community Expert
Community Expert
September 1, 2017
Answered

Identify an instance by the name

  • September 1, 2017
  • 1 reply
  • 2298 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
Community Expert
marlitonCommunity ExpertAuthor
Community Expert
September 1, 2017

Works perfectly! Thanks a lot.

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

Marlon Ceballos
Colin Holgate
Inspiring
September 1, 2017

I am. I should have a sign on me that shows my name. Otherwise I wouldn't have a name property.

There is a good chance that I'll be in Joseph's sessions, if you don't see me elsewhere. Also will be there the day before the conference, doing ACP stuff.