as3 TweenMax,TweenLite的TransformAroundCenterPlugin 类是club的需要收费的
这里提供的代码仅供学习用
共用三个as文件
*/
//---------------------TransformAroundCenterPlugin.as --------------//
/**
* VERSION: 1.00
* DATE: 5/10/2010
* ACTIONSCRIPT VERSION: 3.0
* UPDATES AND DOCUMENTATION AT: http://www.TweenMax.com;
* by a?
**/
package com.greensock.plugins
{
import com.greensock.TweenLite;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Transform;
public class TransformAroundCenterPlugin extends TransformAroundGridPlugin
{
/** @private **/
public static const API:Number = 1.0;
public function TransformAroundCenterPlugin()
{
super();
this.propName = "transformAroundCenter";
this.overwriteProps = ["scaleX
case 0:
_point = new Point(0, 0);
break;
case 1:
_point = new Point(target.width / 2, 0);
break;
case 2:
_point = new Point(target.width, 0);
break;
case 3:
_point = new Point(0, target.height / 2);
break;
case 4:
_point = new Point(target.width / 2, target.height / 2);
break;
case 5:
_point = new Point(target.width, target.height / 2);
break;
case 6:
_point = new Point(0, target.height);
break;
case 7:
_point = new Point(target.width / 2, target.height);
break;
case 8:
_point = new Point(target.width, target.height);
break;
}
}
value.point = new Point(_matrix.tx + _point.x * matrix.a + _point.y * matrix.c, _matrix.ty + _point.x * matrix.b + _point.y * matrix.d);
_transform.matrix = matrix;
super.onInitTween(target, value, tween);
return true;
}
}
}
//---------------------TransformAroundPointPlugin.as --------------//
/**
* VERSION: 1.00
* DATE: 5/10/2010
* ACTIONSCRIPT VERSION: 3.0
* UPDATES AND DOCUMENTATION AT: http://www.TweenMax.com;
* by a?
**/
package com.greensock.plugins
{
import com.greensock.plugins.TransformMatrixPlugin;
import com.greensock.TweenLite;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Transform;
public class TransformAroundPointPlugin extends TransformMatrixPlugin
{
/** @private **/
public static const API:Number = 1.0;
/** @private **/
private static const _DEG2RAD:Number = Math.PI / 180;
/** @private **/
private static const _RAD2DEG:Number = 180 / Math.PI;
/** @private **/
protected var _point:Point;
public function TransformAroundPointPlugin()
{
super();
this.propName = "transformAroundPoint";
this.overwriteProps = ["scaleX
scaleX = -scaleX;
}
var scaleY:Number = Math.sqrt(matrix.c * matrix.c + matrix.d * matrix.d); //Bugs in the Flex framework prevent DisplayObject.scaleY from working consistently, so we must determine it using the matrix.
if (matrix.d < 0 && matrix.a > 0) {
scaleY = -scaleY;
}
var angle:Number = Math.atan2(matrix.b, matrix.a); //Bugs in the Flex framework prevent DisplayObject.rotation from working consistently, so we must determine it using the matrix
if (matrix.a < 0 && matrix.d >= 0) {
angle += (angle <= 0) ? Math.PI : -Math.PI;
}
var finalAngle:Number = ("rotation" in value) ? (typeof(value.rotation) == "number") ? value.rotation * _DEG2RAD : Number(value.rotation) * _DEG2RAD + angle : angle;
if (finalAngle != angle) {
if ("rotation" in value) {
_angleChange = finalAngle - angle;
finalAngle = angle; //to correctly affect the skewX calculations below
} else {
matrix.rotate(finalAngle - angle);
}
}
if ("scale" in value) {
ratioX = Number(value.scale) / scaleX;
ratioY = Number(value.scale) / scaleY;
if (typeof(value.scale) != "number") { //relative value
ratioX += 1;
ratioY += 1;
}
} else {
if ("scaleX" in value) {
ratioX = Number(value.scaleX) / scaleX;
if (typeof(value.scaleX) != "number") { //relative value
ratioX += 1;
}
}
if ("scaleY" in value) {
ratioY = Number(value.scaleY) / scaleY;
if (typeof(value.scaleY) != "number") { //relative value
rati
oY += 1;
}
}
}
if (ratioX) {
matrix.a *= ratioX;
matrix.b *= ratioX;
}
if (ratioY) {
matrix.c *= ratioY;
matrix.d *= ratioY;
}
_aChange = matrix.a - _aStart;
_bChange = matrix.b - _bStart;
_cChange = matrix.c - _cStart;
_dChange = matrix.d - _dStart;
scaleX = Math.sqrt(matrix.a * matrix.a + matrix.b * matrix.b);
if (matrix.a < 0 && matrix.d > 0) {
scaleX = -scaleX;
}
scaleY = Math.sqrt(matrix.c * matrix.c + matrix.d * matrix.d);
if (matrix.d < 0 && matrix.a > 0) {
scaleY = -scaleY;
}
}
_point = ("point" in value && value.point is Point) ? Point(value.point) : new Point(_txStart, _tyStart);
_txChange = (_point.x - _txStart) * (1 - scaleX);
_tyChange = (_point.y - _tyStart) * (1 - scaleY);
return true;
}
override public function set changeFactor(n:Number):void
{
_matrix.a = _aStart + (n * _aChange);
_matrix.b = _bStart + (n * _bChange);
_matrix.c = _cStart + (n * _cChange);
_matrix.d = _dStart + (n * _dChange);
var origin:Matrix = new Matrix(1, 0, 0, 1, 0, 0);
if (_angleChange) {
_matrix.rotate(_angleChange * n);
origin.rotate(_angleChange * n);
}
_matrix.tx = _txStart + (n * _txChange);
_matrix.ty = _tyStart + (n * _tyChange);
var _disX:Number = (_matrix.tx - _point.x) * origin.a + (_matrix.ty - _point.y) * origin.c - (_matrix.tx - _point.x);
var _disY:Number = (_matrix.tx - _point.x) * origin.b + (_matrix.ty - _point.y) * origin.d - (_matrix.ty - _point.y);
_matrix.tx += _disX;
_matrix.ty += _disY;
_transform.matrix = _matrix;
}
private function getRotation(start:Number, end:Number):Number {
var diff:Number = (end - start) % 360;
if (diff != diff % 180) {
diff = (diff < 0) ? diff + 360 : diff - 360;
}
return start + diff;
}
}
}