forked from: MacのDockのようなもの
Mac持ってないんでうろ覚えですが・・・
// forked from handle's MacのDockのようなもの
// Mac持ってないんでうろ覚えですが・・・
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
public class Main extends Sprite {
private const ICON_NUM:int = 7;
public function Main() {
// 台座
var base:MovieClip = new MovieClip();
base.graphics.beginFill(0x555555);
base.graphics.drawRoundRect(0, 0, 440, 30, 15, 15);
base.graphics.endFill();
stage.addChild(base);
base.x = 10;
base.y = 300;
// アイコン
for(var i:int = 0; i < ICON_NUM; i++) {
// アイコンの作成
var icon:MovieClip = createIcon((i + 1).toString());
// あとはコンテナクラスに丸投げ
var container:Container = new Container(stage, icon, i * 60 + 50, 290);
}
}
// アイコンを作って返す
private function createIcon(char:String) :MovieClip {
var icon:MovieClip = new MovieClip();
icon.graphics.beginFill(0x000000);
icon.graphics.drawCircle(0, 0, 23);
icon.graphics.endFill();
var format:TextFormat = new TextFormat();
format.size = 24;
var tf:TextField = new TextField();
tf.text = char;
tf.textColor = 0xFFFFFF;
tf.selectable = false;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.setTextFormat(format);
icon.addChild(tf);
tf.x = -(tf.width / 2);
tf.y = -(tf.height / 2);
return icon;
}
}
}
import flash.events.*;
import flash.display.*;
class Container extends Sprite {
private static const MEASURE:Number = 100;
private var mStage:Stage;
private var mIcon:MovieClip;
private var mX:Number;
private var mY:Number;
public function Container(stage:Stage, icon:MovieClip, x:Number, y:Number) :void {
mStage = stage;
mIcon = icon;
mX = x;
mY = y;
icon.x = mX;
icon.y = mY;
this.addEventListener(Event.ENTER_FRAME, this.scaleChange);
mStage.addChild(mIcon);
}
private function scaleChange(evt:Event) :void {
if(mIcon.y - mStage.mouseY > 50 || mStage.mouseY - mIcon.y > mIcon.height / 2) {
mIcon.x = mX;
mIcon.y = mY;
mIcon.scaleX = 1;
mIcon.scaleY = 1;
return;
}
// カーソルとアイコンの距離に応じて倍率を変える
var scale:Number = (2 * MEASURE - Math.abs(mIcon.x - mStage.mouseX)) / MEASURE;
if(scale < 1.0) scale = 1.0; // 小さくはならない
mIcon.scaleX = scale;
mIcon.scaleY = scale;
mIcon.y = mY + (mIcon.height / 4) * (1.0 - scale);
// X位置を変化
var dx:Number = (mIcon.x - mStage.mouseX) / MEASURE;
mIcon.x = mX + dx * Math.exp(-dx * dx) * MEASURE / 4;;
}
}