GoASAP Tween Platform for ActionScript 3.0

I finally found some free time at the beginning of the month to work with the AS3 Go Tween platform. It’s still in its infancy, but I hope to continue to build/contribute to it. Donovan Adams already has started an object syntax Go Tween class, but I could imagine a filter class, volume class, physics class, etc.

So, why am I still fiddling with this instead of using the perfectly satisfactory Tweener or TweenLite, you ask? Check the benchmarks.

Honestly, it’s not just the benchmarks, it’s the philosophy this project provides. Oh, and it also has built-in sequencing, something I’ve really missed from my AS2 + Fuse days.

Anyway, here’s a simple colorTransform tween class I quickly threw together. Hopefully, someone’ll find this and integrate it into something better…
/**
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.hauckinteractive.tween {
import flash.display.DisplayObject;
import org.goasap.items.LinearGo;
import flash.geom.ColorTransform;
/**
* Simple Tween class that changes the tint of a DisplayObject.
* @author Rich Hauck
* @version 2008-01-07
*/
public class ColorTransformTween extends LinearGo{
protected var _target : DisplayObject;
protected var _targetTint : Number;
protected var _startColor:ColorTransform;
protected var _endColor:ColorTransform;
/**
* Constructor.
* @param target DisplayObject
* @param tint Hexidecimal value (0xFFFFFF)
* @param delay Delay in seconds before performing tween
* @param duration Number of seconds for animation to play
* @param easing type of easing
* */
public function ColorTransformTween(target:DisplayObject = null, tint:Number=NaN, delay:Number = NaN, duration:Number = NaN, easing:Function = null){
super(delay, duration, easing);
_target = target;
_targetTint = tint;
}
/**
* Instantiates and auto-starts class.
* */
public static function go(target:DisplayObject = null, tint:Number=NaN, delay:Number = NaN, duration:Number = NaN, easing:Function = null):void {
var ctTween:ColorTransformTween = new ColorTransformTween(target, tint, duration, delay, easing);
ctTween.start();
}
/**
* Begins tween.
* @return Boolean true if _target is defined.
* */
override public function start():Boolean{
if (!_target){
return false;
}
_startColor = _target.transform.colorTransform;
_endColor = new ColorTransform();
if(!isNaN(_targetTint)){
_endColor.color = _targetTint;
}
return (super.start());
}
/**
* Loop performing tween.
*
* */
override protected function onUpdate(type:String) : void {
_target.transform.colorTransform = interpolateColor(_startColor, _endColor, _position);
}
/**
* Mixes between starting colorTransform and target ending colorTransform.
* @param start current colorTransform of DisplayObject
* @param end target colorTransform of DisplayObject
* @param t incrementing value from 0 to 1
* @ return ColorTransform instance.
* */
private function interpolateColor(start:ColorTransform, end:ColorTransform, t:Number):ColorTransform {
var result:ColorTransform = new ColorTransform();
result.redMultiplier = start.redMultiplier + (end.redMultiplier - start.redMultiplier)*t;
result.greenMultiplier = start.greenMultiplier + (end.greenMultiplier - start.greenMultiplier)*t;
result.blueMultiplier = start.blueMultiplier + (end.blueMultiplier - start.blueMultiplier)*t;
result.alphaMultiplier = start.alphaMultiplier + (end.alphaMultiplier - start.alphaMultiplier)*t;
result.redOffset = start.redOffset + (end.redOffset - start.redOffset)*t;
result.greenOffset = start.greenOffset + (end.greenOffset - start.greenOffset)*t;
result.blueOffset = start.blueOffset + (end.blueOffset - start.blueOffset)*t;
result.alphaOffset = start.alphaOffset + (end.alphaOffset - start.alphaOffset)*t;
return result;
}
}
}

One Response to “GoASAP Tween Platform for ActionScript 3.0”

  1. Azizajalal Says:

    That’s great, I am definitely going to purchase this, it’s just what I need. I have been using a separate program altogether for these kind of effects – Vectoraster, by Lost Minds. But having it as an actual plugin is very attractive.

    Tint

Leave a Reply


Bad Behavior has blocked 349 access attempts in the last 7 days.