Apply and Remove tint to an Object in AS3

If you want to tint an object and then revert to its original color, you can use setTint() passing 0 in the second parameter, e.g.:

Actionscript:
  1. c.setTint (0xFF0000, 0);

Actionscript:
  1. import fl.motion.Color;
  2.  
  3. var square:Sprite = new Sprite();
  4. square.graphics.beginFill(0x000000);
  5. square.graphics.drawRect(100, 100, 100, 100);
  6.  
  7. addChild(square);
  8.  
  9. square.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
  10. square.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
  11.  
  12. function onMouseOver (e:MouseEvent):void
  13. {
  14.     var c:Color = new Color();
  15.     c.setTint (0x929218, 1);
  16.  
  17.     square.transform.colorTransform = c;
  18. }
  19.  
  20. function onMouseOut (e:MouseEvent):void
  21. {
  22.     var c:Color = new Color();
  23.     c.setTint (0, 0);
  24.    
  25.     square.transform.colorTransform = c;
  26. }

About nuno mira

flash developer
This entry was posted in AS3, ActionScript, Flash. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>