Transparent PNGs and Flash
December 10, 2012 12:13 PM Subscribe
Flash CS5/actionscript 3 - how to click through transparent pngs?
I have 2 movie clips and inside each movie clip is a transparent png, the 2 movie clips overlap such that the non-transparent areas of the pngs are touching but do not overlap. Both movie clips are linked to the same actionscript class - so they have the same onclick event. In the areas where the bounding boxes overlap the top one receives the click event even if it is transparent in the area that is being clicked.
That's a simplified example of what's going on, in actuality there are 3 instances of the same movie clip, all in the same place. The movie clip has numerous transparent pngs imported from photoshop - 1 per frame and actionscript determines which frame to display at any given time. The pngs appear to be solid objects though, even if I 'break apart' the transparent areas still highlight when the object is selected and seem to be inseparable. Trace Bitmap allows only the solid area to be clickable but image quality is lost - including making straight edges curved, (some are quite complex shapes and they really do need that tiny bit of edge aliasing to look their best.
Is there a solution? I googled the problem but didn't find much help, most solutions relied on checking the alpha transparency of the pixel under the mouse and only doing x if it wasn't transparent but as far as I can tell the bottom one doesn't even receive the click event.
posted by missmagenta to computers & internet (10 answers total)
A really quick way to do this is to add: stage.addChild(instanceNameOfMovieClip) to the actions for each specific frame. So, each frame would have this code.
What this will do is take the movie clip and make it the top most layer. Every time you enter a frame (assuming you are entering with gotoAndPlay(2) and not gotoAndStop(2)) it will make that movie clip the topmost one.
If this is the same movieclip and same event listener in all the frames, then why not just have one single movie clip that spans across all the frames?
posted by royalsong at 12:31 PM on December 10, 2012