[Tweener] _colorTransform and _brightness

Chris Hinkley chris.hinkley at targetscope.com
Wed Aug 22 11:37:18 PDT 2007


I am currently working on a project where _colorTransform and  
_brightness would be rather useful. After doing some research it  
seemed like these hadn't been completed yet, so I took it upon myself  
to whip something up. Here is some info to help get them up and  
running. Please keep in mind I only spent like 30 minutes on these  
two things. There is probably room for improvement, however, they  
serve me well for now. Also note, that _colorTransform and  
_brightness both manipulate the target's colorTransform object so  
using them simultaneously is not possible at the moment.

*ACTIONSCRIPT 3*

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
=-=-=-=-=-

To use the _colorTransform property with Tweener, you must first  
modify your caurina.transitions.SpecialPropertiesDefault.as

Search for the _colorTransform_splitter() function and replace this:

<CODE>

if (p_value.ra != undefined) nArray.push({name:"_color_ra",  
value:p_value.ra});
if (p_value.rb != undefined) nArray.push({name:"_color_rb",  
value:p_value.rb});
if (p_value.ga != undefined) nArray.push({name:"_color_ba",  
value:p_value.ba});
if (p_value.gb != undefined) nArray.push({name:"_color_bb",  
value:p_value.bb});
if (p_value.ba != undefined) nArray.push({name:"_color_ga",  
value:p_value.ga});
if (p_value.bb != undefined) nArray.push({name:"_color_gb",  
value:p_value.gb});
if (p_value.aa != undefined) nArray.push({name:"_color_aa",  
value:p_value.aa});
if (p_value.ab != undefined) nArray.push({name:"_color_ab",  
value:p_value.ab});

</CODE>

with this:

<CODE>

if (p_value.redMultiplier != undefined) nArray.push 
({name:"_color_ra", value:p_value.redMultiplier});
if (p_value.redOffset != undefined) nArray.push({name:"_color_rb",  
value:p_value.redOffset});
if (p_value.blueMultiplier != undefined) nArray.push 
({name:"_color_ba", value:p_value.blueMultiplier});
if (p_value.blueOffset != undefined) nArray.push({name:"_color_bb",  
value:p_value.blueOffset});
if (p_value.greenMultiplier != undefined) nArray.push 
({name:"_color_ga", value:p_value.greenMultiplier});
if (p_value.greenOffset != undefined) nArray.push({name:"_color_gb",  
value:p_value.greenOffset});
if (p_value.alphaMultiplier != undefined) nArray.push 
({name:"_color_aa", value:p_value.alphaMultiplier});
if (p_value.alphaOffset != undefined) nArray.push({name:"_color_ab",  
value:p_value.alphaOffset});

</CODE>

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
=-=-=-=-=-

To se the _brightness property with Tweener, you must first modify  
your caurina.transitions.SpecialPropertiesDefault.as

Add this line in the init() function:

<CODE>

Tweener.registerSpecialProperty("_brightness", _brightness_get,  
_brightness_set);

</CODE>

and add these functions somewhere in the class:

<CODE>

public static function _brightness_get (p_obj:Object) : Number {
	return p_obj.transform.colorTransform.redOffset ? (1 -  
p_obj.transform.colorTransform.redMultiplier) :  
(p_obj.transform.colorTransform.redMultiplier - 1);
}
	
public static function _brightness_set (p_obj:Object,  
b_value:Number) : void {
	if (b_value > 1) b_value = 1;
	else if (b_value < -1) b_value = -1;
				
	var percent:Number = 1 - Math.abs(b_value);
	var offset:Number  = 0;
	
	if (b_value > 0) offset = b_value * 255;
	
	p_obj.transform.colorTransform = new ColorTransform 
(percent,percent,percent,p_obj.transform.colorTransform.alphaMultiplier, 
offset,offset,offset,p_obj.transform.colorTransform.alphaOffset);
	//trace("Brightness:",_brightness_get 
(p_obj),"Percent:",percent,p_obj.transform.colorTransform.redMultiplier, 
"Offset",offset);
}


</CODE>

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
=-=-=-=-=-

Test Document Class:

<CODE>

package  {

	//> Import Classes
	//-- -- -- -- -- -- -- -- -- -- --
	import flash.geom.ColorTransform;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import caurina.transitions.Tweener;

	public class ColorTransformTest extends Sprite{

		//> Private Properties
		//-- -- -- -- -- -- -- -- -- -- --
		private var circle : Sprite;
		private var ct : ColorTransform;

		//> Public Properties
		//-- -- -- -- -- -- -- -- -- -- --
		

		//> Constructor
		//-- -- -- -- -- -- -- -- -- -- --
		public function ColorTransformTest() {
			circle = new Sprite();
			circle.x = stage.stageWidth/2;
			circle.y = stage.stageHeight/2;
			circle.graphics.beginFill(0x000000);
			circle.graphics.drawCircle(0,0,150);
			circle.graphics.endFill();
			addChild(circle);
			
			ct = circle.transform.colorTransform;
			trace(ct);
			
			addEventListener(MouseEvent.MOUSE_UP, changeColor)			
		}

		//> Private Methods
		//-- -- -- -- -- -- -- -- -- -- --
		private function changeColor(e:MouseEvent) : void {
			var newColor : uint = Math.random() * 0xFFFFFF;
			
			ct.color = newColor;
			trace(ct);

			//Un-comment/comment out whichever you would like to test.
			//------------------
			Tweener.addTween(circle, {_colorTransform:ct, time:1,  
transition:"easeOutExpo"});
			//Tweener.addTween(circle, {_brightness:1, time:1,  
transition:"easeOutExpo"});
		}

		//> Public Methods
		//-- -- -- -- -- -- -- -- -- -- --
        	

	}
}


</CODE>


Hope this helped some folks. I apologize if this has already been done.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.caurinauebi.com/pipermail/tweener-caurinauebi.com/attachments/20070822/0db0817e/attachment.htm 


More information about the Tweener mailing list