tween_class.as
来自「这是《Flash MX编程与创意实现》的源代码」· AS 代码 · 共 125 行
AS
125 行
/*
Tween Class v1.2
Oct. 29, 2002
(c) 2002 Robert Penner
The Tween class provides a versatile framework
for dynamic motion tweening with ActionScript.
Dependencies:
- Motion class
- Object.superCon() (found in core_setup.as)
- Function.extend() (found in core_setup.as)
- Penner easing equations (easing_equations.as)
(strictly speaking, these equations are not mandatory; however, they are usually used with Tween)
Events:
onMotionChanged
onMotionFinished
onMotionLooped
onMotionStarted
onMotionStopped
onMotionResumed
Discussed in Chapter 7 of
Robert Penner's Programming Macromedia Flash MX
http://www.robertpenner.com/profmx
http://www.amazon.com/exec/obidos/ASIN/0072223561/robertpennerc-20
*/
if (typeof _global.Motion != 'function') trace (">> Error: superclass missing - Motion");
if (typeof Object.superCon != 'function') trace (">> Error: Object.superCon() missing (core_setup.as)");
/* constructor for Tween class
obj: reference - the object to which the Tween is targetted
prop: string - the property (of obj) that will be affected
func: reference - a function that calculates a position at a certain time
begin: number - the value of prop at the start of the tween
finish: number - the value of prop when the tween finishes
duration: number - the length of time of the motion; set to infinity if negative or omitted
useSeconds: boolean - a flag specifying whether to use seconds instead of frames
*/
_global.Tween = function (obj, prop, func, begin, finish, duration, useSeconds) {
this.superCon (obj, prop, begin, duration, useSeconds);
this.setFunc (func);
this.setFinish (finish);
};
Tween.extend (Motion);
var TP = Tween.prototype;
//////// PUBLIC METHODS
TP.toString = function () {
return "[Tween obj=" + this.obj + " prop=" + this.prop +
" beg=" + this.begin + " fin=" + this.finish + " dur=" + this.duration +
" t=" + this.time +
" pos=" + this.getPosition() + "]";
};
TP.continueTo = function (finish, duration) {
this.setBegin (this.getPosition());
this.setFinish (finish);
if (duration != undefined)
this.setDuration (duration);
this.start();
};
TP.yoyo = function () {
with (this) {
continueTo (getBegin(), getTime());
}
};
//////// GETTER/SETTER METHODS
TP.getPosition = function (t) {
if (t == undefined) t = this.$time;
with (this) return $func (t, $begin, $change, $duration);
};
TP.setFunc = function (f) {
this.$func = f;
};
TP.getFunc = function () {
return this.$func;
};
TP.setChange = function (c) {
this.$change = c;
};
TP.getChange = function () {
return this.$change;
};
TP.setFinish = function (f) {
this.$change = f - this.$begin;
};
TP.getFinish = function () {
return this.$begin + this.$change;
};
/////////// GETTER/SETTER PROPERTIES
with (TP) {
addProperty ("func", getFunc, setFunc);
addProperty ("change", getChange, setChange);
addProperty ("finish", getFinish, setFinish);
}
delete TP;
trace (">> Tween class loaded");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?