flash on 2010-4-26
/**
* Copyright 084 ( http://wonderfl.net/user/084 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/tILK
*/
package {
import flash.display.Sprite;
public class Tutorial6 extends Sprite {
public function Tutorial6() {
var dock:Dock = new Dock();
dock.x = 150;
dock.y = 180;
addChild(dock);
}
}
}
import flash.display.Sprite;
import flash.events.Event;
class Dock extends Sprite {
private var iconAry : Array = new Array(10);
private var dockTop:int = -30;
function Dock() {
for (var i:int = 0; i < 10; i++) {
iconAry[i] = new Sprite();
iconAry[i].graphics.lineStyle(1, 0xff6600);
iconAry[i].graphics.beginFill(0xff6600);
iconAry[i].graphics.drawCircle(0, -15, 15);
iconAry[i].graphics.endFill();
addChild(iconAry[i]);
iconAry[i].x = 30 * i + 15;
}
addEventListener(Event.ENTER_FRAME, IconMove);
}
private function IconMove(event:Event):void {
for (var i:int = 0 ; i < 10; i++) {
if (0 < mouseX && mouseX < 300 && dockTop < mouseY && mouseY < 0) {
dockTop = -120;
var distance:int = mouseX - (i * 30 +15);
if ( -20 * Math.PI < distance && distance < 20 * Math.PI) { //この範囲内にある時に拡大する。0になる値の範囲内で。←最大値
iconAry[i].scaleY += ((1 + 3 * Math.cos(distance / 40))-iconAry[i].scaleY)/1.5; //20 * Math.PIは約62.8で、コサイン値がちょうど0になる。40はひっくり返らないように調整。
iconAry[i].scaleX += ((1 + 3 * Math.cos(distance / 40))-iconAry[i].scaleX)/1.5;
iconAry[i].x += (i * 30 + 15 - 120 * Math.sin(distance / 40 )-iconAry[i].x)/1.5;
}else {
iconAry[i].scaleY += (1-iconAry[i].scaleY)/1.5;
iconAry[i].scaleX += (1-iconAry[i].scaleX)/1.5;
//iconAry[i].x = i * 30 + 15;
if ( -20 * Math.PI > distance) {
iconAry[i].x += (i * 30 + 15 + 120 + 25 -iconAry[i].x)/1.5;
}else {
iconAry[i].x += (i * 30 +15 - 120 - 5 -iconAry[i].x)/1.5;
}
}
}else{
dockTop = -30;
for (i = 0; i < 10; i++) {
iconAry[i].scaleY += (1 - iconAry[i].scaleY)/1.5;
iconAry[i].scaleX += (1 - iconAry[i].scaleX)/1.5;
iconAry[i].x += (i * 30 + 15 - iconAry[i].x)/1.5;
}
}
}
}
}