AS3 Convert DisplayObject to Black and White


/ Published in: ActionScript 3
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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);

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.