package { import caurina.transitions.Tweener; import caurina.transitions.AuxFunctions; public class PaperVisionColorMaterialProperty { //this package is based on the package caurina.transitions.SpecialPropertiesDefault and //allows you to tween the color of a colorMaterial. public function PaperVisionColorMaterialProperty () { trace ("PaperVisionColorMaterialProperty is a static class and should not be instantiated.") } /** * Registers all the special properties to the Tweener class, so the Tweener knows what to do with them. */ public static function init():void { // pv3d Tweener.registerSpecialProperty("_material_color_r", _material_color_property_get, _material_color_property_set, ["redOffset"]); Tweener.registerSpecialProperty("_material_color_g", _material_color_property_get, _material_color_property_set, ["greenOffset"]); Tweener.registerSpecialProperty("_material_color_b", _material_color_property_get, _material_color_property_set, ["blueOffset"]); Tweener.registerSpecialPropertySplitter("fillColor", _material_color_splitter); } /** * Splits the fillColor parameter into specific color variables * * @param p_value Number The original _color value * @return Array An array containing the .name and .value of all new properties */ public static function _material_color_splitter (p_value:*):Array { var nArray:Array = new Array(); if (p_value == null) { // No parameter passed, so just resets the color nArray.push({name:"_material_color_r", value:0}); nArray.push({name:"_material_color_g", value:0}); nArray.push({name:"_material_color_b", value:0}); } else { // A color tinting is passed, so converts it to the object values nArray.push({name:"_material_color_r", value:AuxFunctions.numberToR(p_value)}); nArray.push({name:"_material_color_g", value:AuxFunctions.numberToG(p_value)}); nArray.push({name:"_material_color_b", value:AuxFunctions.numberToB(p_value)}); } return nArray; } public static function _material_color_property_get (p_obj:Object, p_parameters:Array):Number { var colorProperty:Number = 0; if(p_parameters[0] == "redOffset") colorProperty = AuxFunctions.numberToR(p_obj.fillColor) ; else if(p_parameters[0] == "greenOffset") colorProperty = AuxFunctions.numberToG(p_obj.fillColor) ; else if(p_parameters[0] == "blueOffset") colorProperty = AuxFunctions.numberToB(p_obj.fillColor) ; return colorProperty; } public static function _material_color_property_set (p_obj:Object, p_value:Number, p_parameters:Array):void { var colorProperty:Number = p_obj.fillColor; switch(p_parameters[0]){ case "redOffset" : colorProperty = (colorProperty & 0x00ffff) | (p_value << 16); break; case "greenOffset" : colorProperty = (colorProperty & 0xff00ff) | (p_value << 8); break; case "blueOffset" : colorProperty = (colorProperty & 0xffff00) | (p_value << 0); break; } p_obj.fillColor = colorProperty; } } }