影片添加广播新消息的功能,并能存贮和恢复影片初始信息
//给影片添加广播消息的功能,并能存贮和恢复影片初始信息,请专家提点意见.
//可用#include "MCFunction.as"导入影片
//添加影片广播消息的功能
/*
属性: preX
preY
PreXscale
PreYscale
preRotation
newX
newY
newXscale
newYscale
newRotation
方法: toString()
sendPositionXY() //发送影片位置改变的消息
sendPositionXYScale()
sendPositionRotation()
saveInit()
resetInit()
resetListeners()
事件: onChangeXY
onChangeXYScale
onChangeRotation
*/
//----------------设置影片广播消息功能
AsBroadcaster.initialize(MovieClip.prototype);
//------------定义方法
var MCP = MovieClip.prototype;
MCP.toString = function() {
return this._name;
};
MCP.resetListeners = function() {
this._listeners = new Array();
//this.addListener(this);
};
MCP.sendPositionXY = function() {
this.broadcastMessage("onChangeXY", this);
};
MCP.sendPositionXYScale = function() {
this.broadcastMessage("onChangeXYScale", this);
};
MCP.sendPositionRotation = function() {
this.broadcastMessage("onChangeRotation", this);
};
//保存影片初始信息
MCP.saveInit = function() {
this.initX = this._x;
this.initY = this._y;
this.initXscale = this._xscale;
this.initYscale = this._yscale;
this.initRotation = this._rotation;
this.initAlpha = this._alpha;
this.initHeight = this._height;
this.initWidth = this._width;
};
//重置影片初始信息
MCP.resetInit = function() {
this._x = this.initX;
this._y = this.initY;
this._xscale = this.initXscale;
this._yscale = this.initYscale;
this._rotation = this.initRotation;
this._alpha = this.initAlpha;
this._height = this.initHeight;
this._width = this.initWidth;
};
//-------------------设置新的影片属性
//获取前一位置的x
MCP.getPreX = function() {
return this.$preX;
};
//获取前一位置的Y
MCP.getPreY = function() {
return this.$preY;
};
//获取现位置的NewX
MCP.getNewX = function() {
return this.$newX;
};
//获取现位置的NewY
MCP.getNewY = function() {
return this.$newY;
};
//设置新的位置的X
MCP.setNewX = function(x) {
this.$newX = this._x=x;
if (this.$newX != this.$preX) {
this.sendPositionXY();
}
this.$preX = x;
};
//设置新的位置的Y
MCP.setNewY = function(y) {
this.$newY = this._y=y;
if (this.newY != this.$preY) {
this.sendPositionXY();
}
this.$preY = y;
};
//-----------------------------
//设置新的放缩和旋转变量_xscale,_yscale,_rotation
//获取前一位置的_xscale
MCP.getPreXscale = function() {
return this.$preXscale;
};
//获取前一位置的_yscale
MCP.getPreYscale = function() {
return this.$preYscale;
};
//获取前一位置的_rotation
MCP.getPreRotation = function() {
return this.$preRotation;
};
//获取现位置的newXscale
MCP.getNewXscale = function() {
return this.$newXscale;
};
//获取现位置的newYscale
MCP.getNewYscale = function() {
return this.$newYscale;
};
//获取现位置的newRotation
MCP.getNewRotation = function() {
return this.$newRotation;
};
//设置新的位置的newXscale
MCP.setNewXscale = function(xscale) {
this.$newXscale = this._xscale=xscale;
if (this.$newXscale != this.$preXscale) {
this.sendPositionXYScale();
}
this.$preXscale = xscale;
};
//设置新的位置的newYscale
MCP.setNewYscale = function(yscale) {
this.$newYscale = this._yscale=yscale;
if (this.newYscale != this.$preYscale) {
this.sendPositionXYScale();
}
this.$preYscale = yscale;
};
//设置新的位置的newRotation
MCP.setNewRotation = function(rot) {
this.$newRotation = this._rotation=rot;
if (this.$newRotation != this.$preRotation) {
this.sendPositionRotation();
}
this.$preRotation = rot;
};
//------------------
with (MCP) {
addProperty("preX", getPreX, null);
addProperty("preY", getPreY, null);
addProperty("preRotation", getPreRotation, null);
addProperty("preXscale", getPreXscale, null);
addProperty("preYscale", getPreYscale, null);
addProperty("newX", getNewX, setNewX);
addProperty("newY", getNewY, setNewY);
addProperty("newXscale", getNewXscale, setNewXscale);
addProperty("newYscale", getNewYscale, setNewYscale);
addProperty("newRotation", getNewRotation, setNewRotation);
}
ASSetPropFlags(MCP, null, 1);
delete MCP;
trace(">>MCFunction loaded!");
:em02: