ScalePlugin.as
2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* VERSION: 1.13
* DATE: 10/2/2009
* ACTIONSCRIPT VERSION: 3.0
* UPDATES AND DOCUMENTATION AT: http://www.TweenMax.com
**/
package com.greensock.plugins {
import com.greensock.*;
import flash.display.*;
/**
* ScalePlugin combines scaleX and scaleY into one "scale" property. <br /><br />
*
* <b>USAGE:</b><br /><br />
* <code>
* import com.greensock.TweenLite; <br />
* import com.greensock.plugins.TweenPlugin; <br />
* import com.greensock.plugins.ScalePlugin; <br />
* TweenPlugin.activate([ScalePlugin]); //activation is permanent in the SWF, so this line only needs to be run once.<br /><br />
*
* TweenLite.to(mc, 1, {scale:2}); //tweens horizontal and vertical scale simultaneously <br /><br />
* </code>
*
* <b>Copyright 2010, GreenSock. All rights reserved.</b> This work is subject to the terms in <a href="http://www.greensock.com/terms_of_use.html">http://www.greensock.com/terms_of_use.html</a> or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership.
*
* @author Jack Doyle, jack@greensock.com
*/
public class ScalePlugin extends TweenPlugin {
/** @private **/
public static const API:Number = 1.0;
/** @private **/
protected var _target:Object;
/** @private **/
protected var _startX:Number;
/** @private **/
protected var _changeX:Number;
/** @private **/
protected var _startY:Number;
/** @private **/
protected var _changeY:Number;
/** @private **/
public function ScalePlugin() {
super();
this.propName = "scale";
this.overwriteProps = ["scaleX", "scaleY", "width", "height"];
}
/** @private **/
override public function onInitTween(target:Object, value:*, tween:TweenLite):Boolean {
if (!target.hasOwnProperty("scaleX")) {
return false;
}
_target = target;
_startX = _target.scaleX;
_startY = _target.scaleY;
if (typeof(value) == "number") {
_changeX = value - _startX;
_changeY = value - _startY;
} else {
_changeX = _changeY = Number(value);
}
return true;
}
/** @private **/
override public function killProps(lookup:Object):void {
var i:int = this.overwriteProps.length;
while (i--) {
if (this.overwriteProps[i] in lookup) { //if any of the properties are found in the lookup, this whole plugin instance should be essentially deactivated. To do that, we must empty the overwriteProps Array.
this.overwriteProps = [];
return;
}
}
}
/** @private **/
override public function set changeFactor(n:Number):void {
_target.scaleX = _startX + (n * _changeX);
_target.scaleY = _startY + (n * _changeY);
}
}
}