2007/10/23 | CustomCursor as1.0版本
类别(Flash进修) | 评论(0) | 阅读(89) | 发表于 23:52

工作就是工作,没法赶时髦,虽然AS3.0都出来很久了,但我们的一些东西还得用AS1.0来做
AS1.0也是可以写Class的,只是有点怪怪的

类文件 CustomCursor1.0.as  内容如下:

/*用例
#include "CustomCursor1.0.as"
myCursor=new CustomCursor()
myCursor.setCursor("myCursor",[mc1,mc2],{left:0,top:0,right:300,bottom:50})
*/

//构造函数
function CustomCursor() {
 this.eventMC = _root.createEmptyMovieClip("myCursor_eventMC", 7085);
 this.cursorMC = null;
 this.areaObj = null;
 this.targetArr = null;
 this.style = null;
 this.using = true;
 this.onMouseMove = null;
 this.instance = null;
 this.eventMC.parent = this;
 this.eventMC.onMouseMove = function() {
  this.parent.refurbish();
 };
}
//创建自定义光标,设置光标样式和显示区域
CustomCursor.prototype.setCursor = function(style, targetArr, area) {
 this.setCursorStyle(style);
 this.setArea(area);
 this.setTargets(targetArr);
 this.refurbish();
 for (var i in this) {
  trace(i+" = "+this[i]);
 }
};
//设置光标样式
CustomCursor.prototype.setCursorStyle = function(value) {
 this.style = value;
 if (this.style == null) {
  Mouse.show();
  this.cursorMC.removeMovieClip();
  this.cursorMC = null;
  this.onMouseMove = null;
 } else {
  Mouse.hide();
  this.cursorMC = _root.attachMovie(this.style, "myCursor_cursorMC", 7086);
  var mc = this.cursorMC;
  mc._x = _root._xmouse;
  mc._y = _root._ymouse;
  this.onMouseMove = function() {
   mc._x = _root._xmouse;
   mc._y = _root._ymouse;
  };
 }
};
//设置自定义光标的使用区域,obj可以是null,也可以是Object {left:*,right:*,top:*,bottom:*}
CustomCursor.prototype.setArea = function(obj) {
 if (obj != null) {
  obj.left = obj.left == null ? 0 : obj.left;
  obj.right = obj.right == null ? Stage.width : obj.right;
  obj.top = obj.top == null ? 0 : obj.top;
  obj.bottom = obj.bottom == null ? Stage.height : obj.bottom;
 }
 this.areaObj = obj;
};
//设置自定义光标的使用对象MovieClip
CustomCursor.prototype.setTargets = function(arr) {
 this.targetArr = arr;
};
//是否显示自定义光标
CustomCursor.prototype.useStyle = function(use) {
 this.using = use;
 if (this.cursorMC != null) {
  if (use) {
   this.cursorMC._visible = true;
   Mouse.hide();
  } else {
   this.cursorMC._visible = false;
   Mouse.show();
  }
 }
};
//刷新光标
CustomCursor.prototype.refurbish = function() {
 var area = this.areaObj;
 var arr = this.targetArr;
 //当光标位于设定区域内或是位于目标MC上时,显示自定义光标,否则显示默认光标
 var condition1 = area != null && _root._xmouse>area.left && _root._xmouse<area.right && _root._ymouse>area.top && _root._ymouse<area.bottom;
 if (!condition1) {
  var condition2 = false;
  for (var i in arr) {
   if (arr[i].hitTest(_root._xmouse, _root._ymouse, true)) {
    condition2 = true;
    break;
   }
  }
  if (condition2) {
   this.useStyle(true);
   this.onMouseMove();
   updateAfterEvent();
  } else {
   this.useStyle(false);
  }
 } else {
  this.useStyle(true);
  this.onMouseMove();
  updateAfterEvent();
 }
};

0

评论Comments