漸慢接近的方形們
http://wonderfl.net/user/plus.log/codes
/**
* Copyright plus.log ( http://wonderfl.net/user/plus.log )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9SQx
*/
/* http://wonderfl.net/user/plus.log/codes */
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.text.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.geom.Point;
public class PointMove extends Sprite {
var obj:Array;
var shape:Sprite;
var shape0:Sprite;
var shapeSize:uint = 30;
var timer:Timer;
var rollOvered:Boolean = false;
function PointMove() {
drawShapes();
shape0.addEventListener(MouseEvent.ROLL_OVER,onRover);
shape0.addEventListener(MouseEvent.ROLL_OUT,onRout);
timer = new Timer(33);
timer.addEventListener(TimerEvent.TIMER, loop);
timer.start();
}
function drawShapes():void {
var bgColor:uint = 0x990000;
obj = new Array();
shape0 = new Sprite();
shape0.graphics.beginFill(Math.random(),0.5);
shape0.graphics.drawRect(shapeSize,shapeSize,shapeSize,shapeSize*1.6);
shape0.graphics.endFill();
addChild(shape0);
for (var i:int = 1; i<=10; i++) {
shape = new Sprite();
shape.graphics.beginFill(Math.random()*bgColor,0.5);
shape.graphics.drawRect(shapeSize,shapeSize,shapeSize,shapeSize*1.6);
shape.graphics.endFill();
obj.push(shape);
var shapeText:TextField = new TextField();
shapeText.text = i+" ";
shapeText.autoSize = TextFieldAutoSize.CENTER;
shapeText.x = shapeSize;
shapeText.y = shapeSize;
obj[i-1].addChild(shapeText);
addChild(obj[i-1]);
}
}
function onRover(e:MouseEvent):void {
rollOvered = true;
}
function onRout(e:MouseEvent):void {
rollOvered = false;
}
function loop(e:TimerEvent):void {
for (var i:Number = 0; i< obj.length; i++) {
var point:Point = new Point;
if (rollOvered) {
if (i == 0) {
point.x = shape0.x + shapeSize;
point.y = shape0.y;
} else {
point.x = obj[i-1].x + shapeSize;
point.y = obj[i-1].y ;
}
} else {
if (i == 0) {
point.x = shape0.x;
point.y = stage.stageHeight/2;
} else {
point.x = obj[i-1].x;
point.y = obj[i-1].y;
}
}
obj[i].x += (point.x - obj[i].x) /2 ;
obj[i].y += (point.y - obj[i].y) /2 ;
}
}
}
}