MouseFollower
MouseFollower.as
// forked from kadal's Follower
// forked from kadal's Plasma
/* MouseFollower.as */
package {
import flash.display.Sprite;
import flash.display.Graphics;
import flash.display.DisplayObject;
import flash.display.BlendMode;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
[SWF(backgroundColor="#000000", frameRate=30)]
public class MouseFollower extends Sprite {
private const SW:Number = stage.stageWidth;
private const SH:Number = stage.stageHeight;
private var drawArea:Sprite = new Sprite();
private var headerP:Sprite = new Sprite();
private var p:Walker = new Walker();
public function MouseFollower() {
addChild(drawArea);
p.myX = SW/2;
p.myY = SH/2
p.mySpeed = 8;
p.myRad = 0;
p.myWeight = 2;
p.myColor = 0xFFFFFF;
headerP.graphics.beginFill(0xFFFFFF, 1);
headerP.graphics.moveTo(0,-17);
headerP.graphics.lineTo(6,0);
headerP.graphics.lineTo(-6,0);
headerP.graphics.lineTo(0,-17);
headerP.graphics.endFill();
addChild(headerP);
headerP.x = SW/2;
headerP.y = SH/2;
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "_ゴシック";
myTextFormat.size = 11;
myTextFormat.color = 0xFFFFFF;
myTextFormat.align = TextFormatAlign.CENTER;
var myTextField:TextField = new TextField();
myTextField.defaultTextFormat = myTextFormat;
myTextField.autoSize = TextFieldAutoSize.CENTER;
myTextField.text = "CLICK ME";
addChild(myTextField);
myTextField.x = SW/2 - myTextField.width/2;
myTextField.y = SH/2
buttonMode = true;
addEventListener(MouseEvent.CLICK, myWalk);
}
private function myWalk(evt:MouseEvent):void {
removeEventListener(MouseEvent.CLICK, myWalk);
p.graphics.lineStyle(p.myWeight, p.myColor, 1)
p.graphics.moveTo(p.myX, p.myY);
drawArea.addChild(p);
p.addEventListener(Event.ENTER_FRAME, xMove);
addEventListener(MouseEvent.CLICK, myStop);
}
private function xMove(evt:Event):void{
var p:Object = evt.target;
p.myRad = Math.atan2(mouseY - p.myY, mouseX - p.myX);
p.vX = p.mySpeed * Math.cos(p.myRad);
p.vY = p.mySpeed * Math.sin(p.myRad);
p.myX += p.vX;
p.myY += p.vY;
p.graphics.lineStyle(p.myWeight, p.myColor, 1)
p.graphics.lineTo(p.myX, p.myY);
x = -p.myX + SW/2;
y = -p.myY + SH/2;
headerP.x = p.myX;
headerP.y = p.myY;
headerP.rotation = (p.myRad*360)/(2*Math.PI) + 90;
}
private function myStop(evt:MouseEvent):void{
p.removeEventListener(Event.ENTER_FRAME, xMove);
removeEventListener(MouseEvent.CLICK, myStop);
addEventListener(MouseEvent.CLICK, myWalk);
}
}
}
import flash.display.Sprite;
class Walker extends Sprite {
public var myX:Number;
public var myY:Number;
public var vX:Number;
public var vY:Number;
public var mySpeed:Number;
public var myRad:Number;
public var myWeight:Number;
public var myWidth:Number;
public var myColor:Number;
public function Walker(){
}
}