{"id":96,"date":"2008-11-17T00:00:43","date_gmt":"2008-11-17T07:00:43","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=202"},"modified":"2008-11-17T00:00:43","modified_gmt":"2008-11-17T07:00:43","slug":"basic-tint-function","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=96","title":{"rendered":"Basic Tint Function"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\/\/ display object, red (0-255), green, blue, amount (0-1)\r\nfunction tint(dsp:DisplayObject, r:Number, g:Number, b:Number, amount:Number=1):void {\r\n\tif (amount != 1) {\r\n\t\tr *= amount;\r\n\t\tg *= amount;\r\n\t\tb *= amount;\r\n\t}\r\n\tamount = 1-amount;\r\n\tvar ct:ColorTransform = transform.colorTransform;\r\n\tct.redOffset = r;\r\n\tct.redMultiplier = amount;\r\n\tct.greenOffset = g;\r\n\tct.greenMultiplier = amount;\r\n\tct.blueOffset = b;\r\n\tct.blueMultiplier = amount;\r\n\tdsp.transform.colorTransform = ct;\r\n}\r\n\r\n\/\/ test out the tint function on a circle with a stroke:\r\nvar circle:Shape = Shape(addChild(new Shape()));\r\nwith (circle.graphics) {\r\n\tlineStyle(5, 0x339999);\r\n\tbeginFill(0x003333);\r\n\tdrawCircle(0,0,50);\r\n\tx = 100;\r\n\ty = 100;\r\n}\r\n\r\n\/\/ tint the circle 50% green\r\ntint(circle, 0, 255, 0, .5);\r\n<\/pre>\n<p>The ColorTransform object is a little confusing with its &#8220;redMultiplier, redOffset, greenMultiplier etc&#8230;&#8221; properties. Once you understand them it&#8217;s not a big deal, but I still find them a bit cumbersome. So when I just want to tint a clip similar to the way you might tint a clip in the IDE&#8230; I use this tint function. Rather than taking a hexidecimal number it takes values for red, green and blue (0-255) &#8211; and an amount argument (0-1). <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ display object, red (0-255), green, blue, amount (0-1) function tint(dsp:DisplayObject, r:Number, g:Number, b:Number, amount:Number=1):void { if (amount != 1) { r *= amount; g *= amount; b *= amount; } amount = 1-amount; var ct:ColorTransform = transform.colorTransform; ct.redOffset = r; ct.redMultiplier = amount; ct.greenOffset = g; ct.greenMultiplier = amount; ct.blueOffset = b; ct.blueMultiplier = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[3,40,4,60],"class_list":["post-96","post","type-post","status-publish","format-standard","hentry","category-color","tag-actionscript","tag-color","tag-flash","tag-tint"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=96"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/96\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}