Posted By

mhulse on 02/08/10


Tagged

color RGB transform constants as3 setrgb


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

adrianparr
tspitzr


From AS2 to AS3 – Where did it go – setRGB | [mck]


 / Published in: ActionScript 3
 

URL: http://www.matthijskamstra.nl/blog/index.php/2008/07/23/from-as2-to-as3-where-did-it-go-setrgb/

I really like the use of constants and the dollar sign ($) in this class. I have only used $ in jQuery to designate objects. Looks like one might use $ in AS3 classes to designate/differentiate passed-in variables from internal method/global vars.

  1. /**
  2. * Color (AS3), version 1.0
  3. *
  4. * Enter description here
  5. *
  6. * <pre>
  7. * ____ _ ____
  8. * | __| _ __ ___ ___ | | __ |__ |
  9. * | | | '_ ` _ \ / __|| |/ / | |
  10. * | | | | | | | || (__ | < | |
  11. * | |__ |_| |_| |_| \___||_|\_\ __| |
  12. * |____| |____|
  13. *
  14. * </pre>
  15. *
  16. * @class : Color
  17. * @author : Matthijs C. Kamstra [mck]
  18. * @version : 1.0 - class creation (AS3)
  19. * @since : 11-5-2008 0:22
  20. *
  21. */
  22. package nl.matthijskamstra.utils {
  23.  
  24. import flash.display.*;
  25. import flash.events.*;
  26. import flash.geom.ColorTransform;
  27.  
  28. public class Color {
  29.  
  30. // Constants:
  31. public static var CLASS_REF = nl.matthijskamstra.utils.Color;
  32. public static var CLASS_NAME : String = "Color";
  33. public static var LINKAGE_ID : String = "nl.matthijskamstra.utils.Color";
  34.  
  35. /**
  36. * Constructor
  37. *
  38. * @usage import nl.matthijskamstra.utils.Color; // import
  39. * var __Color:Color = new Color ( this );
  40. * @param $targetObj a reference to a movie clip or object
  41. */
  42. public function Color( $targetObj:DisplayObject=null, $colorValue:uint = 0xff3333) {
  43. // trace ( LINKAGE_ID + ' class instantiated');
  44. if ($targetObj == null) { return; }
  45. var newColorTransform:ColorTransform = $targetObj.transform.colorTransform;
  46. newColorTransform.color = $colorValue;
  47. $targetObj.transform.colorTransform = newColorTransform;
  48. }
  49.  
  50. //////////////////////////////////////// Static ///////////////////////////////////////
  51.  
  52. static public function setRGB( $targetObj:DisplayObject = null, $colorValue:uint = 0xff3333) {
  53. return new Color ( $targetObj, $colorValue);
  54. }
  55.  
  56. } // end class
  57.  
  58. } // end package

Report this snippet  

You need to login to post a comment.