5 Replies Latest reply on Jun 12, 2012 9:50 PM by kglad

    BitmapData.Draw with masked movie clip

    okself

      Hi, I'm using BitmapData.Draw to draw a masked movieclip to a bitmap.  Flash behaves very strangely in many different ways.  To give a couple examples:

       

      1) Normally, the position of the mask is relative to the masked object.  Ex. if I Draw() the movie clip at 10,10 and the mask's position is 20,20, then during the Draw() the mask will effectively be at 30,30.  Weird, but consistent.  However, if I Draw() the mask to another surface first, and then Draw() the movie clip, the mask position will be absolute (20,20 in the example).

       

      2) If the mask is cached as a bitmap, then the Draw() will be clipped to the absolute position of the mask, even if the mask is being positioned relatively as in the previous example.

        • 1. Re: BitmapData.Draw with masked movie clip
          okself Level 1

          (Accidentally hit reply before I finished typing).

           

          I'm pretty sure this is just buggy, I can supply an CS4 FLA that demonstrates the inconsistencies, but I was wondering if these problems are well known / are there any workarounds I should try.

          • 2. Re: BitmapData.Draw with masked movie clip
            kglad Adobe Community Professional & MVP

            i'm not sure there are any inconsistancies but, the draw() method "draws" the untransformed object.  ie, it doesn't matter where your movieclip is positioned, unless you use the matrix parameter to adjust for movieclip transforms, the bitmapdata object will look the same (as the untransformed object).

            1 person found this helpful
            • 3. Re: BitmapData.Draw with masked movie clip
              okself Level 1

              Hi kglad, so the transformation of the movieclip that you're Draw()ing is determined by the matrix, but the position of its mask is determined by its _x, _y, etc.  The inconsistencies are in how flash interprets those properties, eg sometimes it takes the _x, _y as relative to the MovieClip that you Draw(), sometimes they're absolute, etc.

               

              I'm trying to work around this by doing the mask myself:

               

              1) Draw the object to be masked to a staging area

              2) Copy the alpha channel of the staging area to a color channel in a second staging area.  Can't do alpha subtraction with BitmapData.draw(), have to copy the alpha to a color channel.

              3) Copy the mask bitmap's alpha channel to a color channel in a third staging area.

              4) Subtract the third staging area from the second

              5) Copy from the second staging area back to the first staging area's alpha channel

              6) Render the first staging area to the target

               

              This technique seems to work, so if perf is OK then my problems are solved.  Still, if anyone has an explanation for the masking problems I'd be interested.  Or, is there a way to send adobe an FLA that demonstrates the problem / would they look at it and fix in a future version of flash?

              • 4. Re: BitmapData.Draw with masked movie clip
                alexvda

                This is an old issue but comes up as first in google when looking for the offset of the mask when drawing a movieclip to a bitmap. The solution that worked for me I found here: http://stackoverflow.com/questions/9096504/as3-get-bitmap-from-movieclip-with-mask

                • 5. Re: BitmapData.Draw with masked movie clip
                  kglad Adobe Community Professional & MVP

                  that's an as3 solution, not as2.