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

Identify an instance by the name

Community Expert ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

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.

Marlon Ceballos.

Views

1.6K

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

LEGEND , Aug 31, 2017 Aug 31, 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.

}

Votes

Translate

Translate
LEGEND ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

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.

}

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 ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

Works perfectly! Thanks a lot.

Are you going to AdobeMax? I need to meet to my JS hero! 🙂

Marlon Ceballos.

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
LEGEND ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

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.

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
LEGEND ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

If you want to get the names of movieclips without having to manually assign a name, there's some code here you can use to extend Animate to support it:

Re: HTML Canvas instance names - Good tricks to getting them?

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 ,
Aug 31, 2017 Aug 31, 2017

Copy link to clipboard

Copied

Great snippet! Tks a lot for sharing.

Marlon Ceballos.

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
New Here ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

@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.

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 03, 2024 May 03, 2024

Copy link to clipboard

Copied

how do you want to reference it?

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
New Here ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

I have a series of "named" movieclips that each contain the same "unnamed" movieclip (on the second frame of the parent MC). I want to play the inner movieclip when a button (targeting the parent MC) is clicked.
I should probably post as a new question since this is a really old thread?

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 03, 2024 May 03, 2024

Copy link to clipboard

Copied

that's not sufficient to reference without substantial coding.  

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 03, 2024 May 03, 2024

Copy link to clipboard

Copied

Hi.

 

You could do something like this:

function playInnerMC(e)
{
	e.currentTarget.gotoAndStop(1);
	e.currentTarget.children[0].gotoAndPlay(1);
}

this.parentMC.on("click", playInnerMC);

 

Regards,

JC

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
New Here ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

LATEST

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