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.
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.
}
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.
}
Copy link to clipboard
Copied
Works perfectly! Thanks a lot.
Are you going to AdobeMax? I need to meet to my JS hero! 🙂
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.
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?
Copy link to clipboard
Copied
Great snippet! Tks a lot for sharing.
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.
Copy link to clipboard
Copied
how do you want to reference it?
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?
Copy link to clipboard
Copied
that's not sufficient to reference without substantial coding.
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
Copy link to clipboard
Copied
I started a new post for my issue here: