📄 wave_motion_class.as
字号:
/*
WaveMotion Class v1.2
Oct. 29, 2002
(c) 2002 Robert Penner
This class is used to produce oscillating movement.
Dependencies:
- Motion class
- Object.superCon() (found in core_setup.as)
- Function.extend() (found in core_setup.as)
Events:
onMotionChanged
onMotionFinished
onMotionLooped
onMotionStarted
onMotionStopped
onMotionResumed
Discussed in Chapter 8 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)");
///////////////////////////////////////////////////////////////////
_global.WaveMotion = function (obj, prop, begin, amp, period, duration, useSeconds) {
this.superCon (obj, prop, begin, duration, useSeconds);
this.setOffset (begin);
this.setAmp (amp);
this.setPeriod (period);
};
WaveMotion.extend (Motion);
var WMP = WaveMotion.prototype;
WMP.getPosition = function (t) {
if (t == undefined) t = this.$time;
return this.$amp *
Math.sin ((t-this.$timeShift) * (2*Math.PI) / this.$period)
+ this.$offset;
};
WMP.setAmp = function (a) {
if (a != undefined) this.$amp = a;
};
WMP.getAmp = function () {
return this.$amp;
};
WMP.setPeriod = function (p) {
if (p != undefined) this.$period = p;
};
WMP.getPeriod = function () {
return this.$period;
};
WMP.setFreq = function (f) {
this.setPeriod (1 / f);
};
WMP.getFreq = function () {
return 1 / this.getPeriod();
};
WMP.setTimeShift = function (t) {
if (t != undefined) this.$timeShift = t;
};
WMP.getTimeShift = function () {
return this.$timeShift;
};
WMP.setOffset = function (f) {
if (f != undefined) this.$offset = f;
};
WMP.getOffset = function () {
return this.$offset;
};
WMP.setWavePhysics = function (amp, period, timeShift, offset) {
this.setAmp (amp);
this.setPeriod (period);
this.setTimeShift (timeShift);
this.setOffset (offset);
};
with (WaveMotion.prototype) {
addProperty ("amp", getAmp, setAmp);
addProperty ("offset", getOffset, setOffset);
addProperty ("period", getPeriod, setPeriod);
addProperty ("freq", getFreq, setFreq);
addProperty ("timeShift", getTimeShift, setTimeShift);
}
delete WMP;
trace (">> WaveMotion class loaded");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -