For my current project at firstborn I wrote a class which can apply any kind of gray scale picture as a mask to a DisplayObject and then fade in and out the picture, depending on the color values of the picture. This can be done in two different ways.

The threshold method cuts out color values, which produces a very crisp border. This method in combination with a PerlinNoise as the grayscale picture for the mask will produce a nice "burn effect", which also explains the name of the class...

The copyChannel method will fade out the color values of the masking picture, which produces a softer transition. This solution is ideal for "lighting effect transitions" for example. Try the black image on the lower left, together with the radial gradient masking picture and the copyChannel method.

A nice side effect of this class is, that designers without actionscript knowledge can now create grayscale pictures, to prototype the image transition they have in mind. The class is still in an early stage, which means the code is far from optimal and it will probably still change a lot, the version you can download below can be used like this:

  1. _burnMask = new BurnMask(BurnMaskMethods.METHOD_COPYCHANNEL);
  2. _burnMask.createBitmapMask(_bmp);
  3.  
  4. _content.cacheAsBitmap = true;
  5. _burnMask.cacheAsBitmap = true;
  6. _content.mask = _burnMask;
  7.  
  8. _burnMask.fadeTo(2, 0);



-
Related files:
BurnMask.as (alpha version)
BurnMaskMethods.as (alpha version)
ColorMatrix.as (needs some work too)




4 Responses to “BurnMask.as - AS3 masking class”

  1. mareike:

    aha.

    ;)


  2. Bren:

    I can’t get this to work for me, even with example code. I am not getting any errors or anything, and it seems to mask the object, but doesn’t fade or anything. I also have to set an x and y for the mask.. no problem, just should probably be noted for some people.


  3. Jens:

    Like stated in the post: this is a very rough, first draft, which means the code is far from perfect. It basically works though (as shown on http://www.controlyourcredit.gov - check the transition from black screen after the intro), so you must be doing something wrong… If you post a link to your code I can have a quick look for you, if you want to, and I will also try to make an example with comments and clean up the code a little bit and post that as soon as possible.


  4. SBL-Photoshop Masking:

    Great work!


Leave a Reply