📄 transitioner.as
字号:
* try to lookup the value in the tween <code>values</code> for the
* target object. If this does not succeed, the property value will be
* retrieved directly from the target object itself as in the immediate
* mode case.</p>
*
* @param o the target object
* @param name the property name string
* @return the property value for the target object, either from the
* target object's tween values, or, failing that, the object itself.
*/
public function getValue(o:Object, name:String):*
{
if (!_immediate) {
var tw:Tween = _lookup[o];
if (tw != null && tw.values[name] != undefined) {
return tw.values[name];
}
}
return Property.$(name).getValue(o);
}
/**
* Sets the delay of the tween for the given object. If the
* transitioner is in immediate mode, this method has no effect.
* @param o the object to set the delay for
* @param delay the delay, in seconds
*/
public function setDelay(o:Object, delay:Number):void
{
if (!_immediate) {
_(o).delay = delay;
}
}
/**
* Gets the delay of the tween for the given object. If the
* transitioner is in immediate mode or no tween has been created for
* the input object, this method returns zero.
* @param o the object to get the delay for
* @return the delay of the tween, or zero if there is no tween
*/
public function getDelay(o:Object):Number
{
if (_immediate) return 0;
var tw:Tween = _lookup[o];
return tw==null ? 0 : tw.delay;
}
/**
* Sets the removal status of a display object with this transition.
* If true, the display object will be removed from its parent in the
* display list when the transition completes. If this transitioner is
* in immediate mode, any removals are performed immediately.
* @param dobj a display object
* @param b true to remove the display object from the display list
* at the end of the transition (the default). If false, the removal
* status will be updated so that the display object will not be
* removed (not applicable in immediate mode).
*/
public function removeChild(dobj:DisplayObject, b:Boolean=true):void
{
if (_immediate && b) {
if (dobj.parent) dobj.parent.removeChild(dobj);
} else if (!_immediate) {
_(dobj).remove = b;
}
}
/**
* Indicates if a display object is scheduled to be removed from the
* display list when this transition completes. This method always
* returns false if this transitioner is in immediate mode.
* @param d a display object
* @return true if the display object will be removed from the display
* list at the end of this transition, false otherwise. This method
* always returns false if the transitioner is in immediate mode.
*/
public function willRemove(d:DisplayObject):Boolean
{
if (_immediate) return false;
var tw:Tween = _lookup[d];
return (tw != null && tw.remove);
}
/** @inheritDoc */
protected override function end():void
{
super.end();
if (_optimize) dispose();
}
/**
* Disposes of the internal state of this transitioner.
* Contained tweens and their interpolators will be collected and
* recycled for future reuse, improving initialization times for
* subsequent transitioners. This method is automatically called at the
* end of the transition if the <code>optimize</code> flag is true.
* Otherwise, this method can be invoked manually when a transitioner
* is no longer needed.
*/
public override function dispose():void
{
while (_trans.length > 0) {
var t:Transition = _trans.pop();
t.dispose();
if (t is Tween) reclaimTween(t as Tween);
}
}
/**
* Computes the approximate size of the given object after this
* transitioner has been run. This calculation is performed by
* applying the final <code>scaleX</code>, <code>scaleY</code>, and
* <code>size</code> values of the object.
* @param d the display object to compute the size for
* @param r a rectangle for storing the results
* @return a rectangle whose <code>width</code> and <code>height</code>
* properties contain the end size values.
*/
public function endSize(d:DisplayObject, r:Rectangle=null):Rectangle
{
if (r==null) r = new Rectangle();
var t:Tween, v:Object, o:Object = Object(d);
var scaleX:Number, scaleY:Number, size:Number;
if (_immediate || (t=_lookup[d])==null) {
r.width = d.width;
r.height = d.height;
} else {
v = t.values;
if (v.hasOwnProperty("scaleX")) {
scaleX = d.scaleX;
d.scaleX = v.scaleX;
}
if (v.hasOwnProperty("scaleY")) {
scaleY = d.scaleY;
d.scaleY = v.scaleY;
}
if (v.hasOwnProperty("size")) {
size = o.size;
o.size = v.size;
}
r.width = d.width;
r.height = d.height;
if (v.hasOwnProperty("scaleX")) d.scaleX = scaleX;
if (v.hasOwnProperty("scaleY")) d.scaleY = scaleY;
if (v.hasOwnProperty("size")) o.size = size;
}
return r;
}
/**
* Computes the approximate bounds of the given object after this
* transitioner has been run. This calculation is performed by
* applying the final <code>scaleX</code>, <code>scaleY</code>,
* <code>size</code>, <code>x</code>, and <code>y</code> values of
* the object.
* @param d the display object to compute the size for
* @param coords the target coordinate space for the bounds
* @return a rectangle whose <code>width</code> and <code>height</code>
* properties contain the end size values.
*/
public function endBounds(d:DisplayObject,
coords:DisplayObject):Rectangle
{
var r:Rectangle = new Rectangle();
var t:Tween, v:Object, o:Object = Object(d);
var scaleX:Number, scaleY:Number, size:Number, x:Number, y:Number;
if (_immediate || (t=_lookup[d])==null) {
r = d.getBounds(coords);
} else {
v = t.values;
if (v.hasOwnProperty("scaleX")) {
scaleX = d.scaleX;
d.scaleX = v.scaleX;
}
if (v.hasOwnProperty("scaleY")) {
scaleY = d.scaleY;
d.scaleY = v.scaleY;
}
if (v.hasOwnProperty("size")) {
size = o.size;
o.size = v.size;
}
if (v.hasOwnProperty("x")) {
x = d.x;
d.x = v.x;
}
if (v.hasOwnProperty("y")) {
y = d.y;
d.y = v.y;
}
r = d.getBounds(coords);
if (v.hasOwnProperty("scaleX")) d.scaleX = scaleX;
if (v.hasOwnProperty("scaleY")) d.scaleY = scaleY;
if (v.hasOwnProperty("size")) o.size = size;
if (v.hasOwnProperty("x")) d.x = x;
if (v.hasOwnProperty("y")) d.y = y;
}
return r;
}
// --------------------------------------------------------------------
private static var _maxPoolSize:int = 10000;
private static var _tweenPool:Array = [];
private static var _count:int = 0;
private static function getTween(o:Object, duration:Number):Tween
{
var tw:Tween;
if (_tweenPool.length > 0) {
tw = _tweenPool.pop();
tw.target = o;
tw.duration = duration;
tw.enabled = true;
} else {
tw = new Tween(o, duration);
}
return tw;
}
private static function reclaimTween(tw:Tween):void
{
if (_tweenPool.length < _maxPoolSize) {
_tweenPool.push(tw);
}
}
} // end of class Transitioner
}
import flare.animate.Transitioner;
import flare.util.Property;
import flash.utils.flash_proxy;
import flash.utils.Proxy;
/**
* Helper class that gets/sets values for a Transitioner.
* This layer of indirection allows us to perform "behind-the-scenes"
* handling while maintaining simple property assignment syntax.
*/
dynamic class ValueProxy extends Proxy
{
private var _trans:Transitioner;
private var _object:Object;
public function ValueProxy(trans:Transitioner) {
_trans = trans;
}
public function init(obj:Object):Object
{
_object = obj;
return this;
}
override flash_proxy function callProperty(methodName:*, ... args):* {
return null;
}
override flash_proxy function getProperty(name:*):* {
return _trans.getValue(_object, name);
}
override flash_proxy function setProperty(name:*, value:*):void {
_trans.setValue(_object, name, value);
}
} // end of class ValueProxy
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -