views:

47

answers:

4

Hello.

I'm trying to know if there's a way in ActionScript 3 to load a PNG image and make some sort of button or sensible area applicable only for the visible area of that PNG??

Maybe there's a simple way to define a polygonal area on execution time, I mean, dynamically and make it sensible to mouse events??

Thanks!

+1  A: 

Consider this:

  • Load the PNG image.

  • Add it into sprite A.

  • Add the polygonal structure into the sprite (added on top of PNG)

  • Add it into a sprite B.

  • Add an event listener to the polygonal sprite B.

  • Add the sprite B into A.

loxxy
will sprite B alpha is set to zero ??
Muhammad Irfan
If the polygonal area needs to be hidden, then set it to 0, else alpha need not be set.
loxxy
+1  A: 

just set mouse events on your image file, essentially turning it into a button, and then draw and set a mask over the "visible area" of the image.

TheDarkInI1978
+2  A: 

I'm assuming you want the non-transparent area of the PNG to be the clickable area. This is a bit tricky, but luckily someone figured it out already. Use this ActionScript utility class called InteractivePNG.

http://blog.mosessupposes.com/?p=40

Matt W
Just what I used,,, thanks!!
Jean Paul
A: 

I think, the simplest method is : In the MouseEvent handler, detect the mouse position whether on the non-transparent area. If YES, go ahead the click logic. Otherwise, ignore it.

And the most accurate mothed is: Use the Bezier curve to draw the exactly-fit shape as the clickable area. But I think this method is too complex, and costs too much cpu.

Mobius