演示:
代码:
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; } } } }}