论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS编程教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

给 Flash MX 增加新功能(2) MovieClip 类

文章类别:Flash AS编程 | 发表日期:2008-10-6 17:36:48


  今天再提供给大家下面几个功能,全部是针对 MovieClip 的,想使用的话加到自己脚本里面去就可以了(浅蓝色框内的脚本可以直接拷贝)。
 让浏览器窗口抖动起来。
 增强鼠标按钮响应,包括右键和第三键等的响应。
 针对某一坐标晃动的 MovieClip,两种方式。
 动态设置 MovieClip 的 FPS。
  ××××××××××
  功能:让浏览器窗口抖动起来。
  作者:cyberfunk
  代码:
Movieclip.prototype.shakewin = function(amount){
getURL("javascript:function shakewin(n){if(parent.moveBy){for(i =
10;i > 0;i--){for(j = n;j > 0;j--
){parent.moveBy(0,i);parent.moveBy(i,0);parent.moveBy(0,
-i);parent.moveBy(-i,0);}}}};shakewin(" + amount + ");void(0)");
}  用法:
onClipEvent(load){
    this.shakewin(3);
}  ××××××××××
  功能:增强鼠标按钮响应,包括右键和第三键等的响应。
  作者:sukimashita.com
  代码:
getMWDown = function ()
{
    return this._onMouseDownEx;
};
setMWDown = function (f)
{
    this._MouseHandler = {_parent:this};
 this._MouseHandler.onMouseDownEx = function (btn) {
     this._parent.onMouseDownEx(btn); };
 this._MouseHandler.onMouseUpEx = function (btn) {
     this._parent.onMouseUpEx(btn); };
 if (f!=undefined) {
     Mouse.addListener(this._MouseHandler);
 } else {
     Mouse.removeListener(this._MouseHandler);
 }
 this._onMouseDownEx = f;
};

getMWUp = function ()
{
    return this._onMouseUpEx;
};
setMWUp = function (f)
{
    this._MouseHandler = {_parent:this};
 this._MouseHandler.onMouseDownEx = function (btn) {
     this._parent.onMouseDownEx(btn); };
 this._MouseHandler.onMouseUpEx = function (btn) {
     this._parent.onMouseUpEx(btn); };
 if (f!=undefined) {
     Mouse.addListener(this._MouseHandler);
 } else {
     Mouse.removeListener(this._MouseHandler);
 }
 this._onMouseUpEx = f;
};
MovieClip.prototype.addProperty("onMouseDownEx", getMWDown, setMWDown);
MovieClip.prototype.addProperty("onMouseUpEx", getMWUp, setMWUp);
delete getMWUp;
delete setMWUp;
delete getMWDown;
delete setMWDown;
// If DXInput is used 8 buttons max possible...
Mouse.LEFT = 1;
Mouse.RIGHT = 2;
Mouse.MIDDLE = 4;
Mouse.MOUSE1 = 1;
Mouse.MOUSE2 = 2;
Mouse.MOUSE3 = 4;
Mouse.MOUSE4 = 5;
Mouse.MOUSE5 = 6;
Mouse._smbdown = function (f)
{
    //trace("_smbdown: ["+f.num+"]: "+f.state);
 if (this._mbpressed==undefined)
 {
     // Init
  this._mbpressed = new Array();
 };
 
 if ((f.state==true) && (!this._mbpressed[f.num]))
 {
     this._mbpressed[f.num] = true;
  this.broadcastMessage("onMouseDownEx", f.num);
 };
 
 if ((f.state==false) && (this._mbpressed[f.num]==true))
 {
     this._mbpressed[f.num] = false;
  this.broadcastMessage("onMouseUpEx", f.num);
 };
};
setInterval(function () {
    for (var num=1; num < 7; num++)
 {
     if (Mouse._mbpressed[num]!=ASNative(800,2)(num))
 {
     Mouse._smbdown({num:num, state:ASNative(800,2)(num)});
 };
  };
}, 50);  用法:
_root.onMouseDownEx = function (btn)
  {
    switch (btn)
 {
     case Mouse.LEFT:
      trace("Left mousebutton was pressed!");
   break;
  case Mouse.RIGHT:
      trace("Right mousebutton was pressed!");
   break;
  case Mouse.MIDDLE:
      trace("Middle mousebutton was pressed!");
   break;
  case Mouse.MOUSE4:
      trace("4th mousebutton was pressed!");
   break;
  case Mouse.MOUSE5:
      trace("5th mousebutton was pressed!");
   break;
 };
};
 _root.onMouseUpEx = function (btn)
 {
   switch (btn)
   {
       case Mouse.LEFT:
        trace("Left mousebutton was released!");
     break;
    case Mouse.RIGHT:
        trace("Right mousebutton was released!");
     break;
    case Mouse.MIDDLE:
        trace("Middle mousebutton was released!");
     break;
    case Mouse.MOUSE4:
        trace("4th mousebutton was released!");
     break;
    case Mouse.MOUSE5:
        trace("5th mousebutton was released!");
     break;
 };
};  ××××××××××
  功能:针对某一坐标晃动的 MovieClip,两种方式。
  作者:wu-tang
  代码:
//2 functions that provide elastic motion.
//Respects Lithium, for providing code base for this one.
Movieclip.prototype.snapDaddy = function(acc,dec,destY,destX){

    this.acc = acc; this.dec = dec; this.destY = destY; this.destX = destX;
 this.currX =  this._x; this.currY = this._y;
 
    this.diffX = this.destX - this.currX;
 this.diffY = this.destY - this.currY;
 
    this.vx = (this.vx + (this.diffX) * 1 / this.acc) / this.dec;
 this.vy = (this.vy + (this.diffY) * 1 / this.acc) / this.dec;
 
    this._x += this.vx;
 this._y += this.vy;
}
Movieclip.prototype.macDaddy = function(ratio,friction,destY,destX) {
    this.ratio = "."+ratio; this.friction = "."+friction;
    this.destY = destY; this.destX = destX;
 
    this.speedX = ((this.destX - this._x) * this.ratio) + (this.speedX * this.friction);
    this.speedY = ((this.destY - this._y) * this.ratio) + (this.speedY * this.friction);
 
    this._x += this.speedX;
    this._y += this.speedY;
}
//enjoy!  用法:
onClipEvent(enterFrame){
 this.snapDaddy(.8, 1.7, _root._ymouse, _root._xmouse)
}

onClipEvent(enterFrame){
    this.macDaddy(8, 7, _root._ymouse, _root._xmouse);
}  ××××××××××
  功能:动态设置 MovieClip 的 FPS。
  作者:wael
  代码:
Movieclip.prototype.setFPS = function(fps)
{
    moviePlay = function (clipName)
 {
     clipName.gotoAndStop(clipName._currentframe + 1);
  if (clipName._currentframe == clipName._totalframes)
      clearInterval( clipNameID );
 }
 clipNameID = setInterval(moviePlay, 1000/fps, this);
}  用法:
Jesus.setFPS(5);

视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058