• 【设为首页】
  • 【收藏闪客居】
当前位置:主页>AS 应用>文章内容
  • AS3制作鼠标跟随效果
  • 来源:greenidea 作者:绿色小游客 2008-06-18 【

演示:

代码:

package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;

public class MouseFollow extends MovieClip {
private var _followSpList : Array;

public function MouseFollow( ) {
init( );
}
private function init( ):void {
_followSpList = new Array( );
initFollowSprite( );
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
/**
                 * 初始化跟踪元件
                 */
private function initFollowSprite( ):void {
_followSpList.push(getSprite( ));
_followSpList.push(getSprite( ));
}
/**
                 * 获取跟踪元件
                 */
private function getSprite( ):Sprite {
var sp : Sprite = new Sprite( );
sp.graphics.beginFill(0);
sp.graphics.drawCircle(0,0,20);
sp.graphics.endFill();
addChild(sp);
return sp;
}
/**
                 * 处理跟踪动画
                 */
private function enterFrameHandler(event : Event):void {
for (var i : int = 0; i < _followSpList.length; i++) {
if (i == 0) {
_followSpList[0].x += (mouseX - _followSpList[0].x) / 5;
_followSpList[0].y += (mouseY - _followSpList[0].y) / 5;
} else {
_followSpList[i].x += (_followSpList[i - 1].x - _followSpList[i].x) / 5;
_followSpList[i].y += (_followSpList[i - 1].y - _followSpList[i].y) / 5;
}
}
}
}
}




上一篇:物理引擎Box2DFlashAS3 2.0.1   下一篇:AS3 JPEG Encoder应用:从Flash中保存图片
  • 用户名:新注册) 密码: 匿名评论
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)


FLASH源文件

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