Copy link to clipboard
Copied
Hi,
I'm a starter in ActionScript and I want to create a custom shaped button.
By a custom shape, I mean a piano button.
I know how to draw the shape with Shape.graphics.lineTo(); and moveTo() ' s,
but I don't know how to add an eventListener to that certain shape.
I mean, when the user clicks inside that custom shape, I want to call a function. How do I do that?
Thanks !
1 Correct answer
When you create the shape, add it as a child of a movieclip or sprite symbol. Then you can target that symbol and assign a MouseEvent.CLICK event listener to it.
Copy link to clipboard
Copied
When you create the shape, add it as a child of a movieclip or sprite symbol. Then you can target that symbol and assign a MouseEvent.CLICK event listener to it.
Copy link to clipboard
Copied
Thanks, Ned !
But if I do that, won't I get the whole MovieClip as the event.target? Then I will get unwanted parts of that (rectangular) MovieClip also listening for mouse.click, right?
Copy link to clipboard
Copied
I don't follow what the issue is that you are describing. The only thing in the movieclip will be the shape that you are drawing (draw it within the movieclip)
Copy link to clipboard
Copied
Yes Ned, you were right.
It works !
I was afraid that the MovieClip (as itself, a rectangular box) will take all the mouse events, but as you said, only the shape inside that MovieClip takes the mouse events.
Thanks !

