?? tweener.as
字號:
* Remove tweenings from a given object from the tweening list.
*
* @param p_tween Object Object that must have its tweens removed
* @param (2nd-last params) Object Property(ies) that must be removed
* @return Boolean Whether or not it successfully removed this tweening
*/
public static function removeTweens (p_scope:Object, ...args):Boolean {
// Create the property list
var properties:Array = new Array();
var i:uint;
for (i = 0; i < args.length; i++) {
if (typeof(args[i]) == "string" && !AuxFunctions.isInArray(args[i], properties)) properties.push(args[i]);
}
// Call the affect function on the specified properties
return affectTweens(removeTweenByIndex, p_scope, properties);
}
/**
* Remove all tweenings from the engine.
*
* @return <code>true</code> if it successfully removed any tweening, <code>false</code> if otherwise.
*/
public static function removeAllTweens ():Boolean {
if (!Boolean(_tweenList)) return false;
var removed:Boolean = false;
var i:uint;
for (i = 0; i<_tweenList.length; i++) {
removeTweenByIndex(i);
removed = true;
}
return removed;
}
/**
* Pause tweenings for a given object.
*
* @param p_scope Object that must have its tweens paused
* @param (2nd-last params) Property(ies) that must be paused
* @return <code>true</code> if it successfully paused any tweening, <code>false</code> if otherwise.
*/
public static function pauseTweens (p_scope:Object, ...args):Boolean {
// Create the property list
var properties:Array = new Array();
var i:uint;
for (i = 0; i < args.length; i++) {
if (typeof(args[i]) == "string" && !AuxFunctions.isInArray(args[i], properties)) properties.push(args[i]);
}
// Call the affect function on the specified properties
return affectTweens(pauseTweenByIndex, p_scope, properties);
}
/**
* Pause all tweenings on the engine.
*
* @return <code>true</code> if it successfully paused any tweening, <code>false</code> if otherwise.
* @see #resumeAllTweens()
*/
public static function pauseAllTweens ():Boolean {
if (!Boolean(_tweenList)) return false;
var paused:Boolean = false;
var i:uint;
for (i = 0; i < _tweenList.length; i++) {
pauseTweenByIndex(i);
paused = true;
}
return paused;
}
/**
* Resume tweenings from a given object.
*
* @param p_scope Object Object that must have its tweens resumed
* @param (2nd-last params) Object Property(ies) that must be resumed
* @return Boolean Whether or not it successfully resumed something
*/
public static function resumeTweens (p_scope:Object, ...args):Boolean {
// Create the property list
var properties:Array = new Array();
var i:uint;
for (i = 0; i < args.length; i++) {
if (typeof(args[i]) == "string" && !AuxFunctions.isInArray(args[i], properties)) properties.push(args[i]);
}
// Call the affect function on the specified properties
return affectTweens(resumeTweenByIndex, p_scope, properties);
}
/**
* Resume all tweenings on the engine.
*
* @return <code>true</code> if it successfully resumed any tweening, <code>false</code> if otherwise.
* @see #pauseAllTweens()
*/
public static function resumeAllTweens ():Boolean {
if (!Boolean(_tweenList)) return false;
var resumed:Boolean = false;
var i:uint;
for (i = 0; i < _tweenList.length; i++) {
resumeTweenByIndex(i);
resumed = true;
}
return resumed;
}
/**
* Do some generic action on specific tweenings (pause, resume, remove, more?)
*
* @param p_function Function Function to run on the tweenings that match
* @param p_scope Object Object that must have its tweens affected by the function
* @param p_properties Array Array of strings that must be affected
* @return Boolean Whether or not it successfully affected something
*/
private static function affectTweens (p_affectFunction:Function, p_scope:Object, p_properties:Array):Boolean {
var affected:Boolean = false;
var i:uint;
if (!Boolean(_tweenList)) return false;
for (i = 0; i < _tweenList.length; i++) {
if (_tweenList[i] && _tweenList[i].scope == p_scope) {
if (p_properties.length == 0) {
// Can affect everything
p_affectFunction(i);
affected = true;
} else {
// Must check whether this tween must have specific properties affected
var affectedProperties:Array = new Array();
var j:uint;
for (j = 0; j < p_properties.length; j++) {
if (Boolean(_tweenList[i].properties[p_properties[j]])) {
affectedProperties.push(p_properties[j]);
}
}
if (affectedProperties.length > 0) {
// This tween has some properties that need to be affected
var objectProperties:uint = AuxFunctions.getObjectLength(_tweenList[i].properties);
if (objectProperties == affectedProperties.length) {
// The list of properties is the same as all properties, so affect it all
p_affectFunction(i);
affected = true;
} else {
// The properties are mixed, so split the tween and affect only certain specific properties
var slicedTweenIndex:uint = splitTweens(i, affectedProperties);
p_affectFunction(slicedTweenIndex);
affected = true;
}
}
}
}
}
return affected;
}
/**
* Splits a tweening in two
*
* @param p_tween Number Object that must have its tweens split
* @param p_properties Array Array of strings containing the list of properties that must be separated
* @return Number The index number of the new tween
*/
public static function splitTweens (p_tween:Number, p_properties:Array):uint {
// First, duplicates
var originalTween:TweenListObj = _tweenList[p_tween];
var newTween:TweenListObj = originalTween.clone(false);
// Now, removes tweenings where needed
var i:uint;
var pName:String;
// Removes the specified properties from the old one
for (i = 0; i < p_properties.length; i++) {
pName = p_properties[i];
if (Boolean(originalTween.properties[pName])) {
originalTween.properties[pName] = undefined;
delete originalTween.properties[pName];
}
}
// Removes the unspecified properties from the new one
var found:Boolean;
for (pName in newTween.properties) {
found = false;
for (i = 0; i < p_properties.length; i++) {
if (p_properties[i] == pName) {
found = true;
break;
}
}
if (!found) {
newTween.properties[pName] = undefined;
delete newTween.properties[pName];
}
}
// If there are empty property lists, a cleanup is done on the next updateTweens() cycle
_tweenList.push(newTween);
return (_tweenList.length - 1);
}
// ==================================================================================================================================
// ENGINE functions -----------------------------------------------------------------------------------------------------------------
/**
* Updates all existing tweenings.
*
* @return Boolean FALSE if no update was made because there's no tweening (even delayed ones)
*/
private static function updateTweens ():Boolean {
if (_tweenList.length == 0) return false;
var i:int;
for (i = 0; i < _tweenList.length; i++) {
// Looping throught each Tweening and updating the values accordingly
if (_tweenList[i] == undefined || !_tweenList[i].isPaused) {
if (!updateTweenByIndex(i)) removeTweenByIndex(i);
if (_tweenList[i] == null) {
removeTweenByIndex(i, true);
i--;
}
}
}
return true;
}
/**
* Remove a specific tweening from the tweening list.
*
* @param p_tween Number Index of the tween to be removed on the tweenings list
* @return Boolean Whether or not it successfully removed this tweening
*/
public static function removeTweenByIndex (i:Number, p_finalRemoval:Boolean = false):Boolean {
_tweenList[i] = null;
if (p_finalRemoval) _tweenList.splice(i, 1);
return true;
}
/**
* Pauses a specific tween.
*
* @param p_tween Number Index of the tween to be paused
* @return Boolean Whether or not it successfully paused this tweening
*/
public static function pauseTweenByIndex (p_tween:Number):Boolean {
var tTweening:TweenListObj = _tweenList[p_tween]; // Shortcut to this tweening
if (tTweening == null || tTweening.isPaused) return false;
tTweening.timePaused = _currentTime;
tTweening.isPaused = true;
return true;
}
/**
* Resumes a specific tween.
*
* @param p_tween Number Index of the tween to be resumed
* @return Boolean Whether or not it successfully resumed this tweening
*/
public static function resumeTweenByIndex (p_tween:Number):Boolean {
var tTweening:TweenListObj = _tweenList[p_tween]; // Shortcut to this tweening
if (tTweening == null || !tTweening.isPaused) return false;
tTweening.timeStart += _currentTime - tTweening.timePaused;
tTweening.timeComplete += _currentTime - tTweening.timePaused;
tTweening.timePaused = undefined;
tTweening.isPaused = false;
return true;
}
/**
* Updates a specific tween.
*
* @param i Number Index (from the tween list) of the tween that should be updated
* @return Boolean FALSE if it's already finished and should be deleted, TRUE if otherwise
*/
private static function updateTweenByIndex (i:Number):Boolean {
var tTweening:TweenListObj = _tweenList[i]; // Shortcut to this tweening
if (tTweening == null || !Boolean(tTweening.scope)) return false;
var isOver:Boolean = false; // Whether or not it's over the update time
var mustUpdate:Boolean; // Whether or not it should be updated (skipped if false)
var nv:Number; // New value for each property
var t:Number; // current time (frames, seconds)
var b:Number; // beginning value
var c:Number; // change in value
var d:Number; // duration (frames, seconds)
var pName:String; // Property name, used in loops
// Shortcut stuff for speed
var tScope:Object; // Current scope
var tProperty:Object; // Property being checked
if (_currentTime >= tTweening.timeStart) {
// Can already start
tScope = tTweening.scope;
if (tTweening.isCaller) {
// It's a 'caller' tween
do {
t = ((tTweening.timeComplete - tTweening.timeStart)/tTweening.count) * (tTweening.timesCalled+1);
b = tTweening.timeStart;
c = tTweening.timeComplete - tTweening.timeStart;
d = tTweening.timeComplete - tTweening.timeStart;
nv = tTweening.transition(t, b, c, d);
if (_currentTime >= nv) {
if (Boolean(tTweening.onUpdate)) {
try {
tTweening.onUpdate.apply(tScope, tTweening.onUpdateParams);
} catch(e:Error) {
handleError(tTweening, e, "onUpdate");
}
}
tTweening.timesCalled++;
if (tTweening.timesCalled >= tTweening.count) {
isOver = true;
break;
}
if (tTweening.waitFrames) break;
}
} while (_currentTime >= nv);
} else {
// It's a normal transition tween
mustUpdate = tTweening.skipUpdates < 1 || !tTweening.skipUpdates || tTweening.updatesSkipped >= tTweening.skipUpdates;
if (_currentTime >= tTweening.timeComplete) {
isOver = true;
mustUpdate = true;
}
if (!tTweening.hasStarted) {
// First update, read all default values (for proper filter tweening)
if (Boolean(tTweening.onStart)) {
try {
tTweening.onStart.apply(tScope, tTweening.onStartParams);
} catch(e:Error) {
handleError(tTweening, e, "onStart");
}
}
for (pName in tTweening.properties) {
var pv:Number = getPropertyValue (tScope, pName);
tTweening.properties[pName].valueStart = isNaN(pv) ? tTweening.properties[pName].valueComplete : pv;
}
mustUpdate = true;
tTweening.hasStarted = true;
}
if (mustUpdate) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -