12 Replies Latest reply on Oct 10, 2008 7:07 AM by adam@blueapplestudio

    Create Mask

    adam@blueapplestudio Level 1
      I have a cast member on stage (“Block”), and need to mask out different parts of it using a cast member not on the stage (“Hole”). Sometimes I need to mask out 3 holes in different locations, and sometimes just one hole.

      I am just starting out with masks and can’t even seem to get rolling. I am using JavaScript, and the below code returns a “Property not found. #mask” error. Any assistance would be appreciated.

      Any help is appreciated.
        • 1. Re: Create Mask
          Level 7
          Some time ago I made a game, and part of the game involved something
          very similar. There is a picture and on top of the picture is a black
          "mask". The user could cut "holes" in the mask to reveal parts of the
          underlying picture. The code I wrote allowed the holes to be rectangles,
          circles, polygons and freehand drawn irregular shapes.

          It is written in regular Lingo (not javascript) but I can send you the
          part of the program that contains the code if you like. I imagine it
          will take some effort to dig out the the relevant parts, because there
          is more in there than just what you are looking for.

          In a nutshell, it maintains a list of "holes", which was really a list
          of the vertices of vector shapes. It would then start with a solid black
          bitmap cast member (the mask) and cut out the holes using imaging lingo
          (extractAlpha, copyPixels, useAlpha, setAlpha, etc).

          If interested email me at d g c w e b AT b e l l s o u t h DOT n e t





          adam@blueapplestudio wrote:
          > I have a cast member on stage (?Block?), and need to mask out different parts
          > of it using a cast member not on the stage (?Hole?). Sometimes I need to mask
          > out 3 holes in different locations, and sometimes just one hole.
          >
          > I am just starting out with masks and can?t even seem to get rolling. I am
          > using JavaScript, and the below code returns a ?Property not found. #mask?
          > error. Any assistance would be appreciated.
          >
          > Any help is appreciated.
          >
          >
          > function exitFrame(me) {
          >
          > function fMaskTest(){
          > member("Block").mask = member("Hole");
          > }
          >
          > fMaskTest();//returns error, prop not found #mask
          >
          > }
          >
          • 2. Re: Create Mask
            adam@blueapplestudio Level 1
            Dave C,

            Thanks for your response. I have sent you an email at the address you listed. All of the code would be fine, but all I really need is the syntax for masking out part of a bitmap on the stage using a different bitmap castmember. I should be able to handle everything else.

            My frustration is from trying to use the code example in the Director MX2004 Scripting Reference (page 839). Despite copying it accurately (I believe) I am still getting an error.
            • 3. Re: Create Mask
              Level 7
              The example you are trying (member.mask) relates to #quickTimeMedia
              members only. You will have to manipulate an alpha channel and apply it
              to your #bitmap member in order to achieve what you describe.
              • 4. Re: Create Mask
                adam@blueapplestudio Level 1
                Isn't there a way to use createMask() to accomplish this? I have been playing with the example here http://help.adobe.com/en_US/Director/11.0/help.html?content=07_Methods_066.html but haven't gotten the result I'd like yet.

                I basically just want to knock out a box shape from a bitmap cast member onstage, and then be able to reset it so there is no knock-out presetn.
                • 5. Re: Create Mask
                  Level 7
                  Yes, you could start with createMask(), but you're still going to have
                  to manipulate the mask produced with imaging lingo and re-apply it to
                  the bitmap member.
                  • 6. Re: Create Mask
                    Production Monkey Level 3
                    Here is a stencil effect behavior that may give you some ideas how to solve your problem.
                    • 8. Re: Create Mask
                      adam@blueapplestudio Level 1
                      Kindaian, I checked out the link and can’t get that code to return any results. I think that I successfully create a new image, but I don’t know how to place that image on the stage. In a separate post* ( http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=187&threadid=1396437) asking about scripted sprite creation with a duplicated image I outlined my broader goal. Below is a synopsis of what I’m trying to accomplish.

                      Imagine cast member 1 is a bitmap of a wall. Each round of the game, I need to place the wall on stage. Additionally, I need to use a different cast member (hole.bmp) to punch 3 to 5 holes through the wall image on the stage. Each round will be different, so I thought that I needed to duplicate the wall every time, otherwise the cast member itself would have more and more holes cut out over time. I need a fresh wall each round.

                      There is a .zip file here (www.blueapplestudio.com/Director/GenerateMask.zip) containing a Director file with my setup. If one of you could take a look at the code and give me some advice I'd appreciate it.


                      *Not trying to cross/double post. Both threads were started with two different questions in mind.
                      • 9. Re: Create Mask
                        Production Monkey Level 3
                        You can lead a horse to water, but you can't make 'em drink.
                        • 10. Re: Create Mask
                          adam@blueapplestudio Level 1
                          Production Monkey-

                          I do appreciate your assistance, and though I didn’t mention it I have tried working with the script you posted.

                          The script you posted successfully delivers a union of the two images, but what I would like to do is use one image’s alpha to subtract area from another image. Attached is the code I altered to try and achieve this.

                          Sincerely not trying to make anyone do my homework here.

                          -Thirsty Horse
                          • 11. Create Mask
                            Production Monkey Level 3
                            Thirsty Horse,

                            Good to hear from you.

                            I believe you are over thinking this and perhaps missed an important line of code from my behavior - "setAlpha()".

                            "setAlpha()" is all you need to punch some holes in a picture. Using your Director file, the code would be:

                            member("capsule").image.setAlpha(member("mask123").image)

                            The caveat being that member("mask123") needs to be an 8-bit grayscale image with exactly the same dimensions as member "capsule".

                            Let me know if that helps.
                            • 12. Re: Create Mask
                              adam@blueapplestudio Level 1
                              Production Monkey,

                              That is what I was looking for. Thanks for your, and everyone else's, assistance and patience.