In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

[BetweenAS3]TextField color tween

...
@author jc at bk-zen.com
Get Adobe Flash player
by bkzen 21 Apr 2010
/**
 * Copyright bkzen ( http://wonderfl.net/user/bkzen )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2Cqx
 */

package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.core.easing.CubicEaseIn;
	import org.libspark.betweenas3.core.easing.CubicEaseOut;
	
	/**
	 * ...
	 * @author jc at bk-zen.com
	 */
	public class FlashTest1 extends Sprite
	{
		private var txt:TextField;
		
		public function FlashTest1() 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			//
			addChild(txt = new TextField());
			txt.textColor = 0x0000FF;
			txt.text = "TESTTESTTEST";
			var updater: ColorUpdater = new ColorUpdater(txt, "textColor");
			BetweenAS3.serial(
				BetweenAS3.from(updater, updater.from(0x00FF00), 2),
				BetweenAS3.to(updater, updater.to(0xFF0000, {x: 100, y: 100}), 2, new CubicEaseIn()),
				BetweenAS3.to(updater, updater.to(0x00FF00, {x: 200, y: 200}), 2, new CubicEaseOut()),
				BetweenAS3.tween(updater, updater.tweenTo(0xFF0000), updater.tweenFrom(0x006699), 2),
				BetweenAS3.tween(updater, updater.tweenTo(0x000000), null, 2)
			).play();
		}
		
	}
}
/**
 * BetweenAS3 で 色をTweenさせるクラス
 * http://wonderfl.net/c/2Cqx
 * @author jc at bk-zen.com
 */
class ColorUpdater
{
	public var target: Object;
	private var propertyName: String;
	private var _r: int;
	private var _g: int;
	private var _b: int;
	private var isInit: Boolean;
	function ColorUpdater(target: Object, propertyName: String)
	{
		this.target = target, this.propertyName = propertyName;
	}
	
	public function to(to: uint, obj: Object = null): Object
	{
		obj = obj ? { target: obj } : { };
		obj.r = (to >> 16) & 0xFF, obj.g = (to >> 8) & 0xFF, obj.b = (to >> 0) & 0xFF;
		isInit = true;
		return obj
	}
	
	public function from(from: uint, obj: Object = null): Object
	{
		obj = obj ? { target: obj } : { };
		obj.r = (from >> 16) & 0xFF, obj.g = (from >> 8) & 0xFF, obj.b = (from >> 0) & 0xFF;
		if (!isInit) 
		{
			var to: uint = target[propertyName];
			_r = (to >> 16) & 0xFF, _g = (to >> 8) & 0xFF, _b = (to >> 0) & 0xFF;
			isInit = true;
		}
		return obj;
	}
	
	public function tweenFrom(from: uint, obj: Object = null): Object
	{
		obj = obj ? { target: obj } : { };
		obj.r = (from >> 16) & 0xFF, obj.g = (from >> 8) & 0xFF, obj.b = (from >> 0) & 0xFF;
		if (!isInit) 
		{
			var to: uint = target[propertyName];
			_r = (to >> 16) & 0xFF, _g = (to >> 8) & 0xFF, _b = (to >> 0) & 0xFF;
			isInit = true;
		}
		return obj;
	}
	
	public function tweenTo(to: uint, obj: Object = null): Object
	{
		obj = obj ? { target: obj } : { };
		obj.r = (to >> 16) & 0xFF, obj.g = (to >> 8) & 0xFF, obj.b = (to >> 0) & 0xFF;
		//isInit = true;
		return obj
	}
	
	public function get r():int { return _r; }
	
	public function set r(value:int):void 
	{
		if (_r == value) return;
		_r = value;
		target[propertyName] = (_r << 16) | (_g << 8) | _b;
	}
	
	public function get g():int { return _g; }
	
	public function set g(value:int):void 
	{
		if (_g == value) return;
		_g = value;
		target[propertyName] = (_r << 16) | (_g << 8) | _b;
	}
	
	public function get b():int { return _b; }
	
	public function set b(value:int):void 
	{
		if (_b == value) return;
		_b = value;
		target[propertyName] = (_r << 16) | (_g << 8) | _b;
	}
}