Skip to main content
marliton
Community Expert
Community Expert
Sep 1, 2017 12:42 AM UTC
Answered

Identify an instance by the name

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 is closed to new replies. Start a new post to keep the conversation going.
Colin Holgate
Colin HolgateCorrect answer
Inspiring
Sep 1, 2017 12:49 AM UTC

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.

}

11 replies

Colin Holgate
Colin HolgateCorrect answer
Inspiring
Sep 1, 2017 12:49 AM UTC

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.

}

Translate
marliton
Community Expert
marlitonCommunity ExpertAuthor
Community Expert
Sep 1, 2017 12:53 AM UTC

Works perfectly! Thanks a lot.

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

Translate
Marlon Ceballos
Colin Holgate
Inspiring
Sep 1, 2017 12:59 AM UTC

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.

Translate