• 【设为首页】
  • 【收藏闪客居】
当前位置:主页>FLASH AS 编程>AS进阶篇>文章内容
  • 给 Flash MX 增加新功能(1) MovieClip 类
  • 来源:闪客帝国 作者:闪客帝国整理 2006-06-26 【

  今天提供给大家下面几个功能,全部是针对 MovieClip 的,想使用的话加到自己脚本里面去就可以了(浅蓝色框内的脚本可以直接拷贝)。
 禁止动画中(timeline)或者单独 MovieClip 中的所有按钮。
 在动画播放过程中将一个 MovieClip 变成一个按钮。
 不用 Timeline 使 MovieClip 运动。
 鼠标双击 movieClip 的检测
  ××××××××××
  功能:禁止动画中(timeline)或者单独 MovieClip 中的所有按钮。
  作者:不详。
  代码:
MovieClip.prototype.disableAllButtons = function(act) {
    for (var counter in this) {
     if (this[counter].__proto__ == Button.prototype) {
      this[counter].enabled = act;
  } else if
  (this[counter].__proto__ == MovieClip.prototype && this[counter]._parent == this)
        {
      this[counter].disableAllButtons(act);
  }
  }
};
ASSetPropFlags(MovieClip.prototype, "disableAllButtons", 7);
  用法:
disableAllButtons(false); // 禁止使用主动画的所有按钮
disableAllButtons(true); // 允许使用主动画的所有按钮
myMC.disableAllButtons(false); // 禁止使用 myMC 内的所有按钮

  ××××××××××
  功能:在动画播放过程中将一个 MovieClip 变成一个按钮。
  作者:senocular
  代码:
MovieClip.prototype.asButton = function(hit, depth){
    var go1 = function(){this.gotoAndStop(1);};
 var go2 = function(){this.gotoAndStop(2);};
 var go3 = function(){this.gotoAndStop(3);};
 var old, comb = function(a,b){return function(){a.call(this);b.call(this);}};
 this.onRollOut= (old = this.onRollOut)? comb(old,go1) : go1;
 this.onReleaseOutside= (old = this.onReleaseOutside)? comb(old,go1) : go1;
 this.onRelease= (old = this.onRelease)? comb(old,go2) : go2;
 this.onRollOver= (old = this.onRollOver)? comb(old,go2) : go2;
 this.onDragOut= (old = this.onDragOut)? comb(old,go2) : go2;
 this.onPress= (old = this.onPress)? comb(old,go3) : go3;
 this.onDragOver= (old = this.onDragOver)? comb(old,go3) : go3;
 if (hit){
     if (!depth){
      if (this._parent[this._name +"_hit"]) {
       depth = this._parent[this._name +"_hit"].getDepth();
   } else depth = ++this._parent.depth;
  }
  var hit_mc = this.duplicateMovieClip(this._name + "_hit", depth);
  hit_mc._visible = false;
  hit_mc.gotoAndStop(4);
  this.hitArea = hit_mc;
 }
 if (this.hitTest(_root._xmouse, _root._ymouse, true)) this.onRollOver();
 else this.gotoAndStop(1);
}
  用法:
mc.onRollOver = function(){trace("over")}
mc.onPress = function(){trace("press")}
mc.asButton(true);
// mc 现在可以像一个按钮一样使用了
// (使用 frames 1-3 然后 4 当做 hitstate)
  ××××××××××
  功能:不用 Timeline 使 MovieClip 运动。
  作者:eno
  代码:
Movieclip.prototype.slide = function(tx,ty,spd,bnd){
    var mc=this;//target movieclip
 var x;
 var y;
 mc.onEnterFrame=function(){
     //define slide interval
  x = ((tx-mc._x)*spd)+(x*bnd);
  mc._x+= x;
  y = ((ty-mc._y)*spd)+(y*bnd);
  mc._y+= y;
  updateAfterEvent();
  if(Math.round(mc._x-tx)==0 and Math.round(mc._y-ty)==0) {
      delete(mc.onEnterFrame);
  }
 }
}
  用法:
movieclip.slip(tx,ty,spd,bnd);
tx : 目标的 x 坐标
ty : 目标的 y 坐标
spd : 运动速度 (must be 0<speed<=1)
bnd : 范围宽度限制 (must be 0<=bound<1)

例子:
movieclip.slip(300,200,.5,.5);

  ××××××××××
  功能:鼠标双击 movieClip 的检测。
  作者:cyberfunk
  代码:
Movieclip.prototype.doDblClick = function(){
    var clickTime = 300,args = [];
 this.press = getTimer();
 if ((this.press - this.lastPress) < clickTime){
     for(var j=1;j < arguments.length;j++){
      args.push(arguments[j]);
     }  
  arguments[0](args);
  this.press = 0;
 }
 this.lastPress = this.press;
}

//测试函数
functionTest = function(args){
    arguments = args;
 for(var j=0;j < arguments.length;j++){
     trace(typeof(arguments[j]));
 }
}
  用法:
// 将这个脚本写在 MovieClip 里面,就可以使用了
onClipEvent(mouseDown){
  doDblClick(_root.functionTest,"Happy 2002",2,[1,2,3]);
}
 




上一篇:趣味教程:戏说类及对象的初始化   下一篇:给 Flash MX 增加新功能(2) MovieClip 类
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)

Copyright © 2006-2008 flashas.net All Rights Reserved.
网站内容咨询: admin#flashas.net (#为@) 联系QQ:40777822 浙ICP备06033001号
(本网站最佳浏览解析度为1024*768, 建议使用IE 6.0或以上版本浏览器。)