Skip to main content
Participant
May 27, 2013
Answered

How to Create a Button From a Shape?

  • May 27, 2013
  • 1 reply
  • 694 views

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 !

This topic has been closed for replies.
Correct answer Ned Murphy

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.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
May 27, 2013

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.

Participant
May 27, 2013

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?

Ned Murphy
Legend
May 27, 2013

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)