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

Identify an instance by the name

Community Expert ,
Aug 31, 2017 Aug 31, 2017

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
2.2K
Translate
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.

}

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

}

Translate
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

Works perfectly! Thanks a lot.

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

Marlon Ceballos
Translate
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

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

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?

Translate
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

Great snippet! Tks a lot for sharing.

Marlon Ceballos
Translate
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

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

Translate
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

how do you want to reference it?

Translate
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

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?

Translate
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

that's not sufficient to reference without substantial coding.  

Translate
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

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

Translate
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
LATEST
Translate
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