?? tweener.as
字號(hào):
for (pName in tTweening.properties) {
tProperty = tTweening.properties[pName];
if (isOver) {
// Tweening time has finished, just set it to the final value
nv = tProperty.valueComplete;
} else {
if (tProperty.hasModifier) {
// Modified
t = _currentTime - tTweening.timeStart;
d = tTweening.timeComplete - tTweening.timeStart;
nv = tTweening.transition(t, 0, 1, d);
nv = tProperty.modifierFunction(tProperty.valueStart, tProperty.valueComplete, nv, tProperty.modifierParameters);
} else {
// Normal update
t = _currentTime - tTweening.timeStart;
b = tProperty.valueStart;
c = tProperty.valueComplete - tProperty.valueStart;
d = tTweening.timeComplete - tTweening.timeStart;
nv = tTweening.transition(t, b, c, d);
}
}
if (tTweening.rounded) nv = Math.round(nv);
setPropertyValue(tScope, pName, nv);
}
tTweening.updatesSkipped = 0;
if (Boolean(tTweening.onUpdate)) {
try {
tTweening.onUpdate.apply(tScope, tTweening.onUpdateParams);
} catch(e:Error) {
handleError(tTweening, e, "onUpdate");
}
}
} else {
tTweening.updatesSkipped++;
}
}
if (isOver && Boolean(tTweening.onComplete)) {
try {
tTweening.onComplete.apply(tScope, tTweening.onCompleteParams);
} catch(e:Error) {
handleError(tTweening, e, "onComplete");
}
}
return (!isOver);
}
// On delay, hasn't started, so returns true
return (true);
}
/**
* Initiates the Tweener--should only be ran once.
*/
public static function init(p_object:* = null):void {
_inited = true;
// Registers all default equations
_transitionList = new Object();
Equations.init();
// Registers all default special properties
_specialPropertyList = new Object();
_specialPropertyModifierList = new Object();
_specialPropertySplitterList = new Object();
SpecialPropertiesDefault.init();
}
/**
* Adds a new function to the available transition list "shortcuts".
*
* @param p_name String Shorthand transition name
* @param p_function Function The proper equation function
*/
public static function registerTransition(p_name:String, p_function:Function): void {
if (!_inited) init();
_transitionList[p_name] = p_function;
}
/**
* Adds a new special property to the available special property list.
*
* @param p_name Name of the "special" property.
* @param p_getFunction Function that gets the value.
* @param p_setFunction Function that sets the value.
*/
public static function registerSpecialProperty(p_name:String, p_getFunction:Function, p_setFunction:Function, p_parameters:Array = null): void {
if (!_inited) init();
var sp:SpecialProperty = new SpecialProperty(p_getFunction, p_setFunction, p_parameters);
_specialPropertyList[p_name] = sp;
}
/**
* Adds a new special property modifier to the available modifier list.
*
* @param p_name Name of the "special" property modifier.
* @param p_modifyFunction Function that modifies the value.
* @param p_getFunction Function that gets the value.
*/
public static function registerSpecialPropertyModifier(p_name:String, p_modifyFunction:Function, p_getFunction:Function): void {
if (!_inited) init();
var spm:SpecialPropertyModifier = new SpecialPropertyModifier(p_modifyFunction, p_getFunction);
_specialPropertyModifierList[p_name] = spm;
}
/**
* Adds a new special property splitter to the available splitter list.
*
* @param p_name Name of the "special" property splitter.
* @param p_splitFunction Function that splits the value.
*/
public static function registerSpecialPropertySplitter(p_name:String, p_splitFunction:Function, p_parameters:Array = null): void {
if (!_inited) init();
var sps:SpecialPropertySplitter = new SpecialPropertySplitter(p_splitFunction, p_parameters);
_specialPropertySplitterList[p_name] = sps;
}
/**
* Starts the Tweener class engine. It is supposed to be running every time a tween exists.
*/
private static function startEngine():void {
_engineExists = true;
_tweenList = new Array();
__tweener_controller__ = new MovieClip();
__tweener_controller__.addEventListener(Event.ENTER_FRAME, Tweener.onEnterFrame);
updateTime();
}
/**
* Stops the Tweener class engine.
*/
private static function stopEngine():void {
_engineExists = false;
_tweenList = null;
_currentTime = 0;
__tweener_controller__.removeEventListener(Event.ENTER_FRAME, Tweener.onEnterFrame);
__tweener_controller__ = null;
}
/**
* Gets a property value from an object.
*
* @param p_obj Object Any given object
* @param p_prop String The property name
* @return Number The value
*/
private static function getPropertyValue(p_obj:Object, p_prop:String):Number {
if (_specialPropertyList[p_prop] != undefined) {
// Special property
if (Boolean(_specialPropertyList[p_prop].parameters)) {
// Uses additional parameters
return _specialPropertyList[p_prop].getValue(p_obj, _specialPropertyList[p_prop].parameters);
} else {
// Doesn't use additional parameters
return _specialPropertyList[p_prop].getValue(p_obj);
}
} else {
// Regular property
return p_obj[p_prop];
}
}
/**
* Sets the value of an object property.
*
* @param p_obj Object Any given object
* @param p_prop String The property name
* @param p_value Number The new value
*/
private static function setPropertyValue(p_obj:Object, p_prop:String, p_value:Number): void {
if (_specialPropertyList[p_prop] != undefined) {
// Special property
if (Boolean(_specialPropertyList[p_prop].parameters)) {
// Uses additional parameters
_specialPropertyList[p_prop].setValue(p_obj, p_value, _specialPropertyList[p_prop].parameters);
} else {
// Doesn't use additional parameters
_specialPropertyList[p_prop].setValue(p_obj, p_value);
}
} else {
// Regular property
p_obj[p_prop] = p_value;
}
}
/**
* Updates the time to enforce time grid-based updates.
*/
public static function updateTime():void {
_currentTime = getTimer();
}
/**
* Ran once every frame. It's the main engine; updates all existing tweenings.
*/
public static function onEnterFrame(e:Event):void {
updateTime();
var hasUpdated:Boolean = false;
hasUpdated = updateTweens();
if (!hasUpdated) stopEngine(); // There's no tweening to update or wait, so it's better to stop the engine
}
/**
* Sets the new time scale.
*
* @param p_time Number New time scale (0.5 = slow, 1 = normal, 2 = 2x fast forward, etc)
*/
public static function setTimeScale(p_time:Number):void {
var i:Number;
if (isNaN(p_time)) p_time = 1;
if (p_time < 0.00001) p_time = 0.00001;
if (p_time != _timeScale) {
if (_tweenList != null) {
// Multiplies all existing tween times accordingly
for (i = 0; i<_tweenList.length; i++) {
_tweenList[i].timeStart = _currentTime - ((_currentTime - _tweenList[i].timeStart) * _timeScale / p_time);
_tweenList[i].timeComplete = _currentTime - ((_currentTime - _tweenList[i].timeComplete) * _timeScale / p_time);
if (_tweenList[i].timePaused != undefined) _tweenList[i].timePaused = _currentTime - ((_currentTime - _tweenList[i].timePaused) * _timeScale / p_time);
}
}
// Sets the new timescale value (for new tweenings)
_timeScale = p_time;
}
}
// ==================================================================================================================================
// AUXILIARY functions --------------------------------------------------------------------------------------------------------------
/**
* Finds whether or not an object has any tweening.
*
* @param p_scope Target object.
* @return <code>true</code> if there's a tweening occuring on this object (paused, delayed, or active), <code>false</code> if otherwise.
*/
public static function isTweening (p_scope:Object):Boolean {
if (!Boolean(_tweenList)) return false;
var i:uint;
for (i = 0; i<_tweenList.length; i++) {
if (_tweenList[i].scope == p_scope) {
return true;
}
}
return false;
}
/**
* Returns an array containing a list of the properties being tweened for this object.
*
* @param p_scope Target object.
* @return Total number of properties being tweened (including delayed or paused tweens).
*/
public static function getTweens (p_scope:Object):Array {
if (!Boolean(_tweenList)) return [];
var i:uint;
var pName:String;
var tList:Array = new Array();
for (i = 0; i<_tweenList.length; i++) {
if (_tweenList[i].scope == p_scope) {
for (pName in _tweenList[i].properties) tList.push(pName);
}
}
return tList;
}
/**
* Returns the number of properties being tweened for a given object.
*
* @param p_scope Target object.
* @return Total number of properties being tweened (including delayed or paused tweens).
*/
public static function getTweenCount (p_scope:Object):Number {
if (!Boolean(_tweenList)) return 0;
var i:uint;
var c:Number = 0;
for (i = 0; i<_tweenList.length; i++) {
if (_tweenList[i].scope == p_scope) {
c += AuxFunctions.getObjectLength(_tweenList[i].properties);
}
}
return c;
}
/* Handles errors when Tweener executes any callbacks (onStart, onUpdate, etc)
* If the TweenListObj specifies an <code>onError</code> callback it well get called, passing the <code>Error</code> object and the current scope as parameters. If no <code>onError</code> callback is specified, it will trace a stackTrace.
*/
private static function handleError(pTweening : TweenListObj, pError : Error, pCallBackName : String) : void{
// do we have an error handler?
if (Boolean(pTweening.onError) && (pTweening.onError is Function)){
// yup, there's a handler. Wrap this in a try catch in case the onError throws an error itself.
try{
pTweening.onError.apply(pTweening.scope, [pTweening.scope, pError]);
}catch (metaError : Error){
trace("## [Tweener] Error:", pTweening.scope, "raised an error while executing the 'onError' handler. Original error:\n", pError.getStackTrace() , "\nonError error:", metaError.getStackTrace());
}
}else{
// o handler, simply trace the stack trace:
if (!Boolean(pTweening.onError)){
trace("## [Tweener] Error: :", pTweening.scope, "raised an error while executing the'" + pCallBackName + "'handler. \n", pError.getStackTrace() );
}
}
}
/**
* Returns the current tweener version.
* @return The identification string of the current Tweener version, composed of an identification of the platform version ("AS2", "AS2_FL7", or "AS3") followed by space and then the version number.
* @example The following code returns the current used version of Tweener:
* <listing version="3.0">
* import caurina.transitions.Tweener;
*
* var tVersion:String = Tweener.getVersion();
* trace ("Using Tweener version " + tVersion + "."); // Outputs: "Using Tweener version AS3 1.24.47."</listing>
*/
public static function getVersion ():String {
return "AS3 1.26.62";
}
// ==================================================================================================================================
// DEBUG functions ------------------------------------------------------------------------------------------------------------------
/**
* Lists all existing tweenings.
*
* @return A string containing the list of all tweenings that currently exist inside the engine.
*/
public static function debug_getList():String {
var ttl:String = "";
var i:uint, k:uint;
for (i = 0; i<_tweenList.length; i++) {
ttl += "["+i+"] ::\n";
for (k = 0; k<_tweenList[i].properties.length; k++) {
ttl += " " + _tweenList[i].properties[k].name +" -> " + _tweenList[i].properties[k].valueComplete + "\n";
}
}
return ttl;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -