SetActualSizePlugin.as
3.27 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
85
86
87
88
89
90
91
/**
* VERSION: 1.02
* DATE: 10/2/2009
* ACTIONSCRIPT VERSION: 3.0
* UPDATES AND DOCUMENTATION AT: http://www.TweenMax.com
**/
package com.greensock.plugins {
import flash.display.*;
import com.greensock.*;
/**
* Some components require resizing with setActualSize() instead of standard tweens of width/height in
* order to scale properly. The SetActualSizePlugin accommodates this easily. You can define the width,
* height, or both. <br /><br />
*
* <b>USAGE:</b><br /><br />
* <code>
* import com.greensock.TweenLite; <br />
* import com.greensock.plugins.TweenPlugin; <br />
* import com.greensock.plugins.SetActualSizePlugin; <br />
* TweenPlugin.activate([SetActualSizePlugin]); //activation is permanent in the SWF, so this line only needs to be run once.<br /><br />
*
* TweenLite.to(myComponent, 1, {setActualSize:{width:200, height:30}});<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 SetActualSizePlugin extends TweenPlugin {
/** @private **/
public static const API:Number = 1.0; //If the API/Framework for plugins changes in the future, this number helps determine compatibility
/** @private **/
public var width:Number;
/** @private **/
public var height:Number;
/** @private **/
protected var _target:Object;
/** @private **/
protected var _setWidth:Boolean;
/** @private **/
protected var _setHeight:Boolean;
/** @private **/
protected var _hasSetSize:Boolean;
/** @private **/
public function SetActualSizePlugin() {
super();
this.propName = "setActualSize";
this.overwriteProps = ["setActualSize","setSize","width","height","scaleX","scaleY"];
this.round = true;
}
/** @private **/
override public function onInitTween(target:Object, value:*, tween:TweenLite):Boolean {
_target = target;
_hasSetSize = Boolean("setActualSize" in _target);
if ("width" in value && _target.width != value.width) {
addTween((_hasSetSize) ? this : _target, "width", _target.width, value.width, "width");
_setWidth = _hasSetSize;
}
if ("height" in value && _target.height != value.height) {
addTween((_hasSetSize) ? this : _target, "height", _target.height, value.height, "height");
_setHeight = _hasSetSize;
}
if (_tweens.length == 0) { //protects against occassions when the tween's start and end values are the same. In that case, the _tweens Array will be empty.
_hasSetSize = false;
}
return true;
}
/** @private **/
override public function killProps(lookup:Object):void {
super.killProps(lookup);
if (_tweens.length == 0 || "setActualSize" in lookup) {
this.overwriteProps = [];
}
}
/** @private **/
override public function set changeFactor(n:Number):void {
updateTweens(n);
if (_hasSetSize) {
_target.setActualSize((_setWidth) ? this.width : _target.width, (_setHeight) ? this.height : _target.height);
}
}
}
}