Skip to content

Instantly share code, notes, and snippets.

@hankpillow
Created September 2, 2010 20:56
Show Gist options
  • Save hankpillow/562932 to your computer and use it in GitHub Desktop.
Save hankpillow/562932 to your computer and use it in GitHub Desktop.
package aze.motion.specials
{
import aze.motion.EazeTween;
import aze.motion.specials.EazeSpecial;
import flash.geom.*
/**
* scrollRect as eaze property
* @author igor almeida ialmeida.com/
* @usage
* eaze(sprite).to(1,{"_scrollRect":new Rectangle(100,0,100,100)})
*/
public class PropertyScrollrect extends EazeSpecial
{
static public function register():void
{
EazeTween.specialProperties["_scrollRect"] = PropertyScrollrect;
}
private var original : Rectangle;
private var targetRect : Rectangle
private var hasScrollRect : Boolean;
private var tmpRect : Rectangle;
public function PropertyScrollrect(target:Object, property:*, value:*, next:EazeSpecial):void{
super(target, property, value, next);
targetRect = value ? value is Rectangle ? value : new Rectangle : new Rectangle
}
override public function init(reverse:Boolean):void
{
tmpRect = new Rectangle;
var rect : Rectangle = target.hasOwnProperty("scrollRect") ? target.scrollRect is Rectangle ? target.scrollRect.clone() : new Rectangle : new Rectangle;
if (reverse){
original = target.clone();
targetRect = rect.clone();
}else{
original = rect.clone();
}
}
override public function update(ke:Number, isComplete:Boolean):void
{
if (target.hasOwnProperty("scrollRect")){
if (isComplete){
target.scrollRect = targetRect;
}
else{
tmpRect.x = original.x + (targetRect.x - original.x) * ke;
tmpRect.y = original.y + (targetRect.y - original.y) * ke;
tmpRect.width = original.width + (targetRect.width - original.width) * ke;
tmpRect.height = original.height + (targetRect.height - original.height) * ke;
target.scrollRect = tmpRect;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment