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

How to Create a Button From a Shape?

New Here ,
May 27, 2013 May 27, 2013

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 !

TOPICS
ActionScript
681
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 , May 27, 2013 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.

Translate
LEGEND ,
May 27, 2013 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.

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 27, 2013 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?

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 ,
May 27, 2013 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)

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 ,
Jun 03, 2013 Jun 03, 2013
LATEST

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 !

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