
{"id":433,"date":"2008-07-23T10:44:04","date_gmt":"2008-07-23T09:44:04","guid":{"rendered":"http:\/\/www.matthijskamstra.nl\/blog\/?p=433"},"modified":"2008-11-10T16:06:32","modified_gmt":"2008-11-10T15:06:32","slug":"from-as2-to-as3-where-did-it-go-setrgb","status":"publish","type":"post","link":"https:\/\/www.matthijskamstra.nl\/blog\/2008\/07\/23\/from-as2-to-as3-where-did-it-go-setrgb\/","title":{"rendered":"From AS2 to AS3 &#8211; Where did it go &#8211; setRGB"},"content":{"rendered":"<div class=\"update\"><strong>Update #1:<\/strong> It seems that .setRGB () has been deprecated in favor of the flash.geom.ColorTransform class. So a little as2 <a href=\"#as2\">update<\/a>.<\/div>\n<p>In some cases I can&#8217;t help thinking that AS3 hasn&#8217;t made our live easier.<br \/>\nThe same happened with the change that happened from the AS2 setRGB to AS3.<\/p>\n<blockquote><p> Specifies an RGB color for a Color object. <\/p><\/blockquote>\n<h3>setRGB<\/h3>\n<p>This is what the <a href=\"http:\/\/livedocs.adobe.com\/flex\/2\/langref\/migration.html\">ActionScript 2.0 Migration<\/a> has to say about this:<\/p>\n<table width='95%' cellpadding=\"2px\">\n<tr style='background-color:silver'>\n<td><strong>ActionScript 2.0<\/strong><\/td>\n<td><strong>ActionScript 3.0<\/strong><\/td>\n<td><strong>Comments<\/strong><\/td>\n<\/tr>\n<tr style='background-color:#F5F5F5'>\n<td>setRGB() Method <\/td>\n<td>flash.geom.ColorTransform.color<\/td>\n<td>The RGB color value can be set by using the color accessor property of the ColorTransform class.<\/td>\n<\/tr>\n<\/table>\n<p>ActionScript 2 example code:<br \/>\n[as]<br \/>\n\/\/ AS2 Code<br \/>\nvar my_color:Color = new Color(my_mc);<br \/>\nmy_color.setRGB(0xFF0000); \/\/ my_mc turns red<br \/>\n[\/as]<\/p>\n<div id=\"as2\">\nAnother AS2 example because: &#8220;The Color class has been deprecated in favor of the flash.geom.ColorTransform class.&#8221;<br \/>\n[as]<br \/>\n\/\/ AS2 Code (The Color class has been deprecated in favor of the flash.geom.ColorTransform class.)<br \/>\nimport flash.geom.ColorTransform;<\/p>\n<p>var colorTrans:ColorTransform = new ColorTransform();<br \/>\ncolorTrans.rgb = 0xFF0000;<br \/>\nvar trans:Transform = new Transform( my_mc);<br \/>\ntrans.colorTransform = colorTrans;[\/as]\n<\/p><\/div>\n<p>and the same code in ActionScript 3:<br \/>\n[as]<br \/>\n\/\/ AS3 code<br \/>\nimport flash.geom.ColorTransform;<\/p>\n<p>\/\/ Changes my_mc&#8217;s color to red.<br \/>\nvar newColorTransform:ColorTransform = my_mc.transform.colorTransform;<br \/>\nnewColorTransform.color = 0xff0000;<br \/>\nmy_mc.transform.colorTransform = newColorTransform;<br \/>\n[\/as]<\/p>\n<p>More code to write, for something that I don&#8217;t use very much. The next time I need to change an Objects color I probably need to search the solution on the web&#8230;<\/p>\n<p>No, I going to fix this in a neat little package:<br \/>\nSave this file into: &#8216;nl.matthijskamstra.utils&#8217;<br \/>\n[as]<br \/>\n\/**<br \/>\n* Color (AS3), version 1.0<br \/>\n*<br \/>\n* Enter description here<br \/>\n*<br \/>\n* <\/p>\n<pre>\r\n*  ____                   _      ____ \r\n* |  __| _ __ ___    ___ | | __ |__  |\r\n* | |   | '_ ` _ \\  \/ __|| |\/ \/    | |\r\n* | |   | | | | | || (__ |   <     | |\r\n* | |__ |_| |_| |_| \\___||_|\\_\\  __| |\r\n* |____|                        |____|\r\n* \r\n* <\/pre>\n<p>*<br \/>\n* @class  \t: \tColor<br \/>\n* @author \t:  \tMatthijs C. Kamstra [mck]<br \/>\n* @version :\t1.0 - class creation (AS3)<br \/>\n* @since \t:\t11-5-2008 0:22<br \/>\n*<br \/>\n*\/<br \/>\npackage nl.matthijskamstra.utils {<\/p>\n<p>\timport flash.display.*;<br \/>\n\timport flash.events.*;<br \/>\n\timport flash.geom.ColorTransform;<\/p>\n<p>\tpublic class Color {<\/p>\n<p>\t\t\/\/ Constants:<br \/>\n\t\tpublic static var CLASS_REF = nl.matthijskamstra.utils.Color;<br \/>\n\t\tpublic static var CLASS_NAME : String = \"Color\";<br \/>\n\t\tpublic static var LINKAGE_ID : String = \"nl.matthijskamstra.utils.Color\";\t<\/p>\n<p>\t\t\/**<br \/>\n\t\t* Constructor<br \/>\n\t\t*<br \/>\n\t\t* @usage   \timport nl.matthijskamstra.utils.Color; \/\/ import<br \/>\n\t\t*\t\t\tvar __Color:Color = new Color ( this );<br \/>\n\t\t* @param\t$targetObj\t\ta reference to a movie clip or object<br \/>\n\t\t*\/<br \/>\n\t\tpublic function Color(   $targetObj:DisplayObject=null, $colorValue:uint = 0xff3333) {<br \/>\n\t\t\t\/\/ trace ( LINKAGE_ID + ' class instantiated');<br \/>\n\t\t\tif ($targetObj == null) { return; }<br \/>\n\t\t\tvar newColorTransform:ColorTransform = $targetObj.transform.colorTransform;<br \/>\n\t\t\tnewColorTransform.color = $colorValue;<br \/>\n\t\t\t$targetObj.transform.colorTransform = newColorTransform;<br \/>\n\t\t}<\/p>\n<p>\t\t\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Static \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<\/p>\n<p>\t\tstatic public function setRGB(  $targetObj:DisplayObject = null, $colorValue:uint = 0xff3333) {<br \/>\n\t\t\treturn new Color ( $targetObj, $colorValue);<br \/>\n\t\t}<\/p>\n<p>\t} \/\/ end class<\/p>\n<p>} \/\/ end package<br \/>\n[\/as]<\/p>\n<p>And now I hope you will never have to look for it again<br \/>\nHappy AS3 ;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update #1: It seems that .setRGB () has been deprecated in favor of the flash.geom.ColorTransform class. So a little as2 update. In some cases I can&#8217;t help thinking that AS3 hasn&#8217;t made our live easier. The same happened with the change that happened from the AS2 setRGB to AS3. Specifies an RGB color for a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,172,3,6],"tags":[68,39,97,408,398,114,168],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-as3","category-as3-migration","category-flash","category-open-source-freeware","tag-actionscript","tag-as2","tag-as2-to-as3","tag-as3","tag-flash","tag-from-as2-to-as3","tag-migration"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/comments?post=433"}],"version-history":[{"count":4,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":689,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/posts\/433\/revisions\/689"}],"wp:attachment":[{"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.matthijskamstra.nl\/blog\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}