Posted By

adrianparr on 04/07/10


Tagged

white colour color and greyscale as3 filters black colormatrixfilter blackandwhite


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tspitzr


AS3 Convert DisplayObject to Black and White


 / Published in: ActionScript 3
 

URL: http://chargedweb.com/labs/2010/03/18/fast-blacknwhite-trick/

This handy little function can be used to convert a displayObject to black and white.

  1. // import flash.filters.ColorMatrixFilter;
  2.  
  3. function blackAndWhite($target:DisplayObject, $enabled:Boolean):void
  4. {
  5. var rc:Number = 1/3;
  6. var gc:Number = 1/3;
  7. var bc:Number = 1/3;
  8. var cmf:ColorMatrixFilter = new ColorMatrixFilter([rc, gc, bc, 0, 0, rc, gc, bc, 0, 0, rc, gc, bc, 0, 0, 0, 0, 0, 1, 0]);
  9.  
  10. if ($enabled) {
  11. $target.filters = [cmf];
  12. } else {
  13. $target.filters = [];
  14. }
  15. }
  16.  
  17. blackAndWhite(myMovieClip, true);

Report this snippet  

You need to login to post a comment.