[Flashcoders] Detecting mouse events over non-white parts of a movieClip
Hi I need to detect mouse events on a movieclip's non-white content rather than it's bounding rectangle even where the contents are bitmap based. I'm putting together an activity for kids where they create a piece of art by dragging and dropping visual elements onto their canvas, then they can subsequently select these elements to move them, resize them, rotate, delete them etc. The user must be able to accurately select these elements even when they are overlapping – so long as a movieClip is partially visible, it needs to be selectable. The problem of course is that the movieClips are responding to mouse events as soon as the mouse enters their bounding rectangle. The items they drag are sourced from photographic material and need to remain as bitmap–based movieClips. They are a collection of everyday items: fruit, plants, vehicles, people etc and currently they are imported as PNGs with an alpha channel. One option would be to make a vector graphic version of every single graphic, have that layered behind in each clip and have that detect the mouse events – but what a pain! There has to be a simpler way? I guess I need seomething like a background transparent blending mode – but there isn't one:( I'm sure others have tackled this problem. Anyone? David ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Detecting mouse events over non-white parts of a movieClip
Check out the BitmapData class, specifically the static loadBitmap(id) method for creating an instance from a library symbol, and getPixel() which allows checking individual pixel values. I would think an algorithm that would work would be to iterate through the display list, do hitTest() on every clip, and for those that hit, starting with the first (which is the highest depth), copy the image data into a BitmapData object and do a getPixel() at that spot to test for the transparent color (which sounds like its white). This would be slow, presumably. But might redo the objects on stage so that they are already Bitmaps or BitmapData. My 2 cents. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Detecting mouse events over non-white parts of a movieClip
Also, just looking this up made me notice that as of Flash 8, you can do pixel-level hit detection between not only a bitmap and a point, but 2 bitmaps, with alpha threshold support! BitmapData.hitTest() On 2/7/07, Jason Boyd [EMAIL PROTECTED] wrote: Check out the BitmapData class, specifically the static loadBitmap(id) method for creating an instance from a library symbol, and getPixel() which allows checking individual pixel values. I would think an algorithm that would work would be to iterate through the display list, do hitTest() on every clip, and for those that hit, starting with the first (which is the highest depth), copy the image data into a BitmapData object and do a getPixel() at that spot to test for the transparent color (which sounds like its white). This would be slow, presumably. But might redo the objects on stage so that they are already Bitmaps or BitmapData. My 2 cents. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Detecting mouse events over non-white parts of a movieClip
Thanks for those suggestions. I didn't think about Birmapdata.hitTest(), but I had thought about using getPixel() Sure, I can use that to decide whether or not the user has clicked on a non-white area, but that doesn't resolve user confusion. It doesn't help the user to know which item they are about to select because the cursor will already have changed when the mouse enters the bounding rect. Cheers David On 8/02/2007, at 4:05 PM, Jason Boyd wrote: Also, just looking this up made me notice that as of Flash 8, you can do pixel-level hit detection between not only a bitmap and a point, but 2 bitmaps, with alpha threshold support! BitmapData.hitTest() On 2/7/07, Jason Boyd [EMAIL PROTECTED] wrote: Check out the BitmapData class, specifically the static loadBitmap (id) method for creating an instance from a library symbol, and getPixel () which allows checking individual pixel values. I would think an algorithm that would work would be to iterate through the display list, do hitTest() on every clip, and for those that hit, starting with the first (which is the highest depth), copy the image data into a BitmapData object and do a getPixel() at that spot to test for the transparent color (which sounds like its white). This would be slow, presumably. But might redo the objects on stage so that they are already Bitmaps or BitmapData. My 2 cents. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Detecting mouse events over non-white parts of a movieClip
Can't you override the onMouseOver of the clips to prevent the cursor change? Or wait, why would the cursor be changing? There's no onRollover event being specifically handled, but each of the clips has onPress, onRelease and onReleaseOutside events handled. My understanding is that it's the default behaviour of a clip with any mouse events handled at all, that the cursor changes when it enters the clip. In the case of a clip comprising a vector graphic the change occurs when it enters a non-white area. In the case of a clip containing a bitmap, it changes when the cursor enters the bounding rectangle of the clip. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Detecting mouse events over non-white parts of a movieClip
cant you just use hitArea and make a transparent vector shape hit state for each visual element? On 2/7/07, Dave Wood [EMAIL PROTECTED] wrote: Hi I need to detect mouse events on a movieclip's non-white content rather than it's bounding rectangle even where the contents are bitmap based. I'm putting together an activity for kids where they create a piece of art by dragging and dropping visual elements onto their canvas, then they can subsequently select these elements to move them, resize them, rotate, delete them etc. The user must be able to accurately select these elements even when they are overlapping – so long as a movieClip is partially visible, it needs to be selectable. The problem of course is that the movieClips are responding to mouse events as soon as the mouse enters their bounding rectangle. The items they drag are sourced from photographic material and need to remain as bitmap–based movieClips. They are a collection of everyday items: fruit, plants, vehicles, people etc and currently they are imported as PNGs with an alpha channel. One option would be to make a vector graphic version of every single graphic, have that layered behind in each clip and have that detect the mouse events – but what a pain! There has to be a simpler way? I guess I need seomething like a background transparent blending mode – but there isn't one:( I'm sure others have tackled this problem. Anyone? David ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- John Van Horn [EMAIL PROTECTED] ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Detecting mouse events over non-white parts of a movieClip
My understanding is that it's the default behaviour of a clip with any mouse events handled at all, that the cursor changes when it enters the clip. Oh right, sorry. So I wonder if it is possible to override this by definining an onMouseOver and changing the cursor to the default one? ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Detecting mouse events over non-white parts of a movieClip
oki just realized you said that would be a pain in your original message. sorry...i am tired. how many elements do you have? a hitArea for each one does seem like a simpler way to goor maybe i'm just tired. On 2/7/07, John VanHorn [EMAIL PROTECTED] wrote: cant you just use hitArea and make a transparent vector shape hit state for each visual element? On 2/7/07, Dave Wood [EMAIL PROTECTED] wrote: Hi I need to detect mouse events on a movieclip's non-white content rather than it's bounding rectangle even where the contents are bitmap based. I'm putting together an activity for kids where they create a piece of art by dragging and dropping visual elements onto their canvas, then they can subsequently select these elements to move them, resize them, rotate, delete them etc. The user must be able to accurately select these elements even when they are overlapping – so long as a movieClip is partially visible, it needs to be selectable. The problem of course is that the movieClips are responding to mouse events as soon as the mouse enters their bounding rectangle. The items they drag are sourced from photographic material and need to remain as bitmap–based movieClips. They are a collection of everyday items: fruit, plants, vehicles, people etc and currently they are imported as PNGs with an alpha channel. One option would be to make a vector graphic version of every single graphic, have that layered behind in each clip and have that detect the mouse events – but what a pain! There has to be a simpler way? I guess I need seomething like a background transparent blending mode – but there isn't one:( I'm sure others have tackled this problem. Anyone? David ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- John Van Horn [EMAIL PROTECTED] -- John Van Horn [EMAIL PROTECTED] ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Detecting mouse events over non-white parts of a movieClip
cant you just use hitArea and make a transparent vector shape hit state for each visual element? As I think I indicated, that is indeed an option, but one we're looking for a way to avoid. Cheers David ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Detecting mouse events over non-white parts of a movieClip
If I were looking for the super-ideal correct algorithm and hade infinite coding monkeys, I would at init time create bitmaps of every library item, and use flood-fill combined with trig math to generate vector trace shapes of the non-white areas, which I would draw as zero alpha shapes into a movie clip attached to each raster movie clip. And then iterate throgh the display list calling hitTest on these invisible shapes. You'd avoid any code to copy bitmap data, would still be able to otherwise treat your clips as normal clips, and would get pre-built hitTest() behavior for the vector shaps, without having extra design-time work when images are added. The code to convert a bitmap into vectors would be the tricky part, but is technically doable. I may be tired as well. Just thinking outside the box. On 2/7/07, Dave Wood [EMAIL PROTECTED] wrote: cant you just use hitArea and make a transparent vector shape hit state for each visual element? As I think I indicated, that is indeed an option, but one we're looking for a way to avoid. Cheers David ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com