3 Replies Latest reply on May 29, 2009 11:26 PM by kglad

    "negative" fill

    mhig9000

      I'm very new to Flash but starting to get the hang of it.

       

      However I've run into a bit of a snag with a project I'm working on.

       

      I basically want to make an animation with an effect similar to the one when you select a portion of an image using the crop tool (background very dark and the selected area unaffected). I have discovered a few different ways to do it, the easiest so far to bring in my bitmap image, lock it in a layer, then put a rectangle the same size and shape as the image in front, fill it with black with an alpha of 50% and then delete parts of the rectangle in the places i want to highlight. Then I drag the edges of the cutouts in to fill the cutout, and use a shape tween to animate. However, I would like these "highlighted" areas to be clickable buttons, and I would not like to have to make a custom layer every time I want to use this animation for a diferent background image (since I will always be highlighting different areas of different images)

       

      So my question is: is there any way to make a "negative object" (for lack of a better term) meaning an object whose fill removes the fill from the object behind it. This would make things much simpler to duplicate for different images over and over again.

       

      Thanks in advance for any responses.

        • 1. Re: "negative" fill
          kglad Adobe Community Professional & MVP

          will the highlighted regions always be rectangular or circular or elliptic?  and are you using as2 or as3?

          • 2. Re: "negative" fill
            mhig9000 Level 1

            I'm using AS3 and the areas could be either rectangular or elliptical (i was hoping for circular but square or rectangular would work fine for my purposes).

            • 3. Re: "negative" fill
              kglad Adobe Community Professional & MVP

              you can use the function below the dotted line.  just pass the movieclip you want to highlight, the highlight shape ("rect" or "ellipse") and the highlight data (which is an object with x,y,width,height properties).

               

              for example, to highlight a movieclip mc with an elliptical shape at 10,20 with width =100 and height=40 use:

               

              highlightF(mc,"ellipse",{x:10,y:20,width:100,height:40});

               

               

               

              //----------------------- nothing below this line needs editing ------------------------------

              function highlightF(mcToHighlight:MovieClip,highlightShape:String,highlightData:Object){
                  var cover:Sprite = new Sprite();
                  with(cover.graphics){
                      beginFill(0x000000,.5);
                      drawRect(mcToHighlight.x,mcToHighlight.y,mcToHighlight.width,mcToHighlight.height);
                      endFill();
                  }
                  var holeSP:Sprite = new Sprite();
                  with(holeSP.graphics){
                      beginFill(0x0f0f00);
                      if(highlightShape=="rect"){
                          drawRect(highlightData.x,highlightData.y,highlightData.width,highlightData.height);
                      } else {
                          drawEllipse(highlightData.x,highlightData.y,highlightData.width,highlightData.height);
                      }
                      endFill();
                  }
                  var bmpd:BitmapData = new BitmapData(cover.width,cover.height,true,0x00000000);
                  bmpd.draw(cover);
                  bmpd.draw(holeSP,null,null,BlendMode.ERASE);
                  var bmp:Bitmap = new Bitmap(bmpd);
                  mcToHighlight.parent.addChildAt(bmp,mcToHighlight.parent.getChildIndex(mcToHighlight)+1);
              }