matrix 5*5 Ver.2
色々と修正していたらソースが汚くなってしまった。(^_^;)
それに余り綺麗に動かないので、違う方法がよいかも。
// forked from keiso's forked from: matrix 5*5
// forked from keiso's matrix 5*5
//色々と修正していたらソースが汚くなってしまった。(^_^;)
//それに余り綺麗に動かないので、違う方法がよいかも。
package
{
import caurina.transitions.Tweener;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.text.TextField;
[SWF(width="465", height="465",backgroundColor="#000000",frameRate="30")]
public class Matrix55ver2 extends Sprite
{
private var mc:MovieClip;
private var g:MovieClip;
private var tf:TextField;
private var numOfCircle:uint = 25;
private var rectSize:uint = 78;
private var rectOffset:uint = 38;
private var zoomScale:Number = 2;
public function Matrix55ver2()
{
var colourArray:Array = [0xE81000,0xFFCA09,0xFF0232,0x001AE8,0x09FF41,0xffffff*Math.random()];
tf = new TextField();
tf.text = "Hello world";
tf.textColor = 0xffffff;
this.addChild(tf);
g = new MovieClip();
this.addChild(g);
for(var i:int=0;i< numOfCircle;i++){
mc = new MovieClip();
mc.graphics.clear();
mc.graphics.lineStyle(1, 0xffffff);
mc.graphics.beginFill(colourArray[Math.round(Math.random()*5)]);
mc.graphics.drawRect(0, 0, rectSize, rectSize);
mc.graphics.endFill();
mc.x = rectSize * (i % 5) + rectOffset;
mc.y = rectSize * Math.round(i / 5 -0.5) + rectOffset;
g.addChild(mc);
}
g.addEventListener(MouseEvent.MOUSE_OVER,onMouseOverHandler);
g.addEventListener(MouseEvent.MOUSE_OUT, onMouseOutHandler);
}
private function onMouseOverHandler(e:MouseEvent):void{
var target:MovieClip = e.target as MovieClip;
var index:int = g.getChildIndex(target);
tf.text = index.toString();
aroundBehavior(index,1/zoomScale);
var pos:Point;
pos = getPos(index);
var w:Number;
var h:Number;
var gotoX:Number;
var gotoY:Number;
if(index % 5 == 0){
w = rectSize + 39 ;
gotoX = pos.x;
}else if(index % 5 == 4){
w = rectSize + 39 ;
gotoX = pos.x-39;
}else{
w = rectSize * zoomScale;
gotoX = pos.x-(rectSize/zoomScale);
}
if(index < 5){
h = rectSize + 39;
gotoY = pos.y;
}else if(index > 19){
h = rectSize + 39
gotoY = pos.y -39;
}else{
h = rectSize*zoomScale;
gotoY = pos.y-(rectSize/zoomScale);
}
Tweener.addTween(e.target, {
width:w,height:h,
// width:rectWidth,height:rectSize,
x:gotoX,
y:gotoY,
// x:pos.x,
// y:pos.y,
time:0.5,
transition:"easeOutCubic"
});
}
private function onMouseOutHandler(e:MouseEvent):void{
var pos:Point;
var target:MovieClip = e.target as MovieClip;
var index:int = g.getChildIndex(target);
tf.text = "";
pos = getPos(index);
aroundBehavior(index,1);
Tweener.addTween(target, {
width:rectSize,height:rectSize,
x:pos.x,
y:pos.y,
time:0.5,
transition:"easeOutCubic"
});
}
private function aroundBehavior(index:int,scale:Number):void{
var target:MovieClip;
var pos:Point;
var current:int;
// var halfOffset:int = offset/2;
var offset:int = rectSize - (rectSize * scale);
var w:Number;
var h:Number;
var gotoX:Number;
var gotoY:Number;
if(index % 5 != 0){
//左
current = index-1;
// tf.text = "左:" + current.toString();
target = g.getChildAt(current) as MovieClip;
pos = getPos(current);
gotoX = pos.x;
if(current < 5){
h = rectSize + offset;
gotoY = pos.y;
}else if(current > 19){
h = rectSize + offset;
gotoY = pos.y-offset;
}else{
h = rectSize * (1 / scale);
gotoY = pos.y-offset;
}
Tweener.addTween(target, {
width:rectSize * scale,height:h,
x:gotoX,y:gotoY,
time:0.5,transition:"easeOutCubic"
});
}
if(index > 5 && index % 5 != 0){
//左上
current = index-6;
// tf.text = "左上:" + current.toString();
target = g.getChildAt(current) as MovieClip;
pos = getPos(current);
Tweener.addTween(target, {
width:rectSize * scale,height:rectSize * scale,
x:pos.x,y:pos.y,
time:0.5,transition:"easeOutCubic"});
// Tweener.addTween(g.getChildAt(index-5), {scaleX:1, scaleY:scale,time:0.5,transition:"easeOutCubic"});
}
if(index > 4){
//上
current = index-5;
// tf.text = "上:" + current.toString();
target = g.getChildAt(current) as MovieClip;
pos = getPos(current);
if(current %5 == 0){
w = rectSize + offset;
gotoX = pos.x ;
}else if(current %5 == 4){
w = rectSize + offset;
gotoX = pos.x-offset;
}else{
w = rectSize * (1 /scale);
gotoX = pos.x-offset;
}
Tweener.addTween(target, {
width:w,height:rectSize * scale,
x:gotoX,y:pos.y,
time:0.5,transition:"easeOutCubic"});
// Tweener.addTween(g.getChildAt(index-5), {scaleX:1, scaleY:scale,time:0.5,transition:"easeOutCubic"});
}
if(index > 3 && index % 5 != 4){
//右上
current = index-4;
// tf.text = "右上:" + current.toString();
target = g.getChildAt(current) as MovieClip;
pos = getPos(current);
Tweener.addTween(target, {
width:rectSize * scale,height:rectSize * scale,
x:pos.x+offset,y:pos.y,
time:0.5,transition:"easeOutCubic"});
// Tweener.addTween(g.getChildAt(index-5), {scaleX:1, scaleY:scale,time:0.5,transition:"easeOutCubic"});
}
if(index % 5 != 4){
//右
current = index+1;
// tf.text = "右:" + current.toString();
target = g.getChildAt(current) as MovieClip;
pos = getPos(current);
gotoX = pos.x+offset;
if(current < 5){
h = rectSize + offset;
gotoY = pos.y;
}else if(current > 19){
h = rectSize + offset;
gotoY = pos.y-offset;
}else{
h = rectSize * (1 / scale)
gotoY = pos.y-offset;
}
Tweener.addTween(target, {
width:rectSize * scale,height:h,
x:gotoX,y:gotoY,
time:0.5,transition:"easeOutCubic"});
// Tweener.addTween(g.getChildAt(index+1), {scaleX:scale, scaleY:1,time:0.5,transition:"easeOutCubic"});
}
if(index < numOfCircle -4 && index % 5 != 0){
//左下
current = index+4;
// tf.text = "左下:" + current.toString();
target = g.getChildAt(current) as MovieClip;
pos = getPos(current);
Tweener.addTween(target, {
width:rectSize * scale,height:rectSize * scale,
x:pos.x,y:pos.y+offset,
time:0.5,transition:"easeOutCubic"});
}
if(index < numOfCircle -5){
//下
current = index+5;
// tf.text = "下:" + current.toString();
target = g.getChildAt(current) as MovieClip;
pos = getPos(current);
if(current %5 == 0){
w = rectSize + offset;
gotoX = pos.x ;
}else if(current %5 == 4){
w = rectSize + offset;
gotoX = pos.x-offset;
}else{
w = rectSize * (1 /scale);
gotoX = pos.x-offset;
}
Tweener.addTween(target, {
width:w,height:rectSize * scale,
x:gotoX,y:pos.y+offset,
time:0.5,transition:"easeOutCubic"});
}
if(index < numOfCircle -6 && index % 5 != 4){
//右下
current = index+6;
// tf.text = "右下:" + current.toString();
target = g.getChildAt(current) as MovieClip;
pos = getPos(current);
Tweener.addTween(target, {
width:rectSize * scale,height:rectSize * scale,
x:pos.x+offset,y:pos.y+offset,
time:0.5,transition:"easeOutCubic"});
}
}
private function getPos(index:int):Point{
var result:Point = new Point();
result.x = rectSize * (index % 5) + rectOffset ;
result.y = rectSize * Math.round(index / 5 -0.5) + rectOffset;
return result;
}
}
}