motioncam_class.as

来自「这是《Flash MX编程与创意实现》的源代码」· AS 代码 · 共 143 行

AS
143
字号
/*
  Tween Class v1.2
  Oct. 29, 2002
  (c) 2002 Robert Penner
  
  A MotionCam instance can record the movement of a single "actor" property onto
  its own "film". It can then play it back, to the same property (the actor)
  or to a different property.
  
  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 13 of 
  Robert Penner's Programming Macromedia Flash MX
  Used in the Fractal Dancer animation.
  
  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.MotionCam = function (obj, prop, duration) {
	this.superCon (obj, prop, obj[prop], duration);
	this.setActor (obj, prop);
	this.film = [];
};

MotionCam.extend (Motion);

var MCP = MotionCam.prototype;


///////// PUBLIC METHODS

MCP.startRecord = function () {
	this.isRecording = true;
};

MCP.stopRecord = function () {
	this.isRecording = false;
};

MCP.cutFilm = function (t) {
	if (t == undefined) var t = this.$time;
	this.film.length = t + 1;
	this.setDuration (t);
};

MCP.eraseFilm = function () {
	this.film = [];
	this.setDuration (0);
};

MCP.toString = function () {
	return "[MotionCam prop=" + this.$prop + " t=" + this.$time + 
		" pos=" + this.$position + " mode: " + this.mode + "]";
};

MCP.print = function () {
	trace (this.getFilmString());
};


////////// GETTER/SETTER METHODS

// overrides abstract method Motion.getPosition()
MCP.getPosition = function (t) {
	if (t == undefined) t = this.$time;
	return this.film[t];
};

MCP.setActorObj = function (ao) {
	this.actorObj = ao;
};

MCP.getActorObj = function () {
	return this.actorObj;
};

MCP.setActorProp = function (ap) {
	this.actorProp = ap;
};

MCP.getActorProp = function () {
	return this.actorProp;
};

MCP.setActor = function (ao, ap) {
	this.setActorObj (ao);
	this.setActorProp (ap);
};

MCP.setFilm = function (film_arr) {
	this.film = film_arr;
};

MCP.getFilm = function () {
	return this.film;
};

MCP.setFilmString = function (str) {
	this.film = str.split (",");
};

MCP.getFilmString = function () {
	return this.film.toString();
};


////////////// PRIVATE METHODS

// overrides Motion.update()
MCP.update = function () {
	if (this.isRecording) 
		with (this) film[$time] = actorObj[actorProp];
	super.update();
};


delete MCP;

trace (">> MotionCam class loaded");


 ////////////////// end MotionCam class //////////////////////////////////////


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?