| ·好听的歌 | ·火影忍者 | ·繁体字转换 | ·在线听歌 | ·火影忍者漫画 | ·最新歌曲 | ·psp游戏下载 | ·photoshop | ·火星文 |
Flash特效制作常用的源代码大放送
作者:龙犊整理 文章来源:天极网 点击数: 更新时间:2006-7-31
两点间的直线移动
| 以下是引用片段: var s = 15; _root.onMouseDown = function() { var oldM_x = _root._xmouse; var oldM_y = _root._ymouse; ax = aa._x; ay = aa._y; dis = Math.sqrt((oldM_x-ax)*(oldM_x-ax)+(oldM_y-ay)*(oldM_y-ay)); xa = (oldM_x-ax)/dis; ya = (oldM_y-ay)/dis; amove(); }; function amove() { onEnterFrame = function () { aa._x += s*xa; aa._y += s*ya; if (Math.sqrt((aa._x-ax)*(aa._x-ax)+(aa._y-ay)*(aa._y-ay))>dis) { delete onEnterFrame; } }; } |
计算两个对象之间/两点之间的距离(注册点)
| 以下是引用片段: function getDistanceOf(target1, target2, x2, y2) { if (arguments.length == 4) { dx = x2-target1; dy = y2-target2; } else if (arguments.length == 2) { dx = target2._x-target1._x; dy = target2._y-target1._y; } return Math.sqrt(dx*dx+dy*dy); } |
//Arguments 对象是一个数组,其中包含作为参数传递给任何函数的值。每次在动作脚本中调用函数时,都会为该函
数自动创建 Arguments 对象。同时还会创建一个局部变量 arguments,使您可引用 arguments 对象。
让播放的MC暂停一段时间
| 以下是引用片段: function pausePlay(sec) { pfunc = function () { this.play(); clearInterval(this.pint); } stop(); this.pint = setInterval(this, "pfunc", sec*1000); } //这样调用.sec是暂停的时间,单位是秒. pausePlay(2); |
onHitTest(target),自己写的一个MC事件,当该MC与指定的MC hitTest的时候触发事件.其实也没什么特别的地方,一样也是用setInterval来实现
| 以下是引用片段: stop(); MovieClip.prototype.listen = function(target) { if (this.isHiting == undefined) { this.isHiting = this.hitTest(target); } if (this.hitTest(target)) { if (this.isHiting == false) { this.broadcastMessage("onHitTest", this, target);//广播事件,给事件传递this和target两个参数 } this.isHiting = true; } else { this.isHiting = false; } };//为MovieClip添加域成员listen成员,用于监视当前对象与目标是否碰撞 MovieClip.prototype.watch = function(target) { this.timer = setInterval(this, "listen", 50, target); };//以每50毫秒检测一次的速度来检测是否碰撞 MovieClip.prototype.unWatch = function() { clearInterval(this.timer); };//停止对对象的监视 ASBroadcaster.initialize(MovieClip.prototype);//初始化MovieClip原型为事件源 //下面是调用的示例 //假设有两个MovieClip,左边ball,右边wall,让ball不断往wall移动,同时监视wall,一旦击中触发事件onHitTest ball.onEnterFrame = function() { this._x += 5; };//让ball不断往右方移动工 myListener = new Object(); myListener.onHitTest = function(source,target){ trace("The " + source._name + " hit " + target._name + "."); }; ball.addListener(myListener);//创建监听员并注册给ball ball.watch(wall);//让ball监视wall |
网友评论
(评论内容只代表网友观点,与本站立场无关!)
相关文章
推荐文章
热门文章
您现在的位置: 


