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.text.TextField;
[SWF(width="465", height="465",backgroundColor="#000000",frameRate="30")]
public class Matrix55 extends Sprite
{
private var mc:MovieClip;
private var g:MovieClip;
private var tf:TextField;
private var numOfCircle:uint = 25;
private var circleWidth:uint = 77;
private var circleHeight:uint = 77;
private var circleOffset:uint = 77;
public function Matrix55()
{
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.beginFill(colourArray[Math.round(Math.random()*5)]);
mc.graphics.drawRect(-25, -25, 50, 50);
mc.graphics.endFill();
mc.x = circleWidth * (i % 5) + circleOffset;
mc.y = circleHeight * Math.round(i / 5 -0.5) + circleOffset;
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.2);
Tweener.addTween(e.target, {
scaleX:1.8, scaleY:1.8,
time:0.5,
transition:"easeOutCubic"
});
}
private function onMouseOutHandler(e:MouseEvent):void{
var target:MovieClip = e.target as MovieClip;
var index:int = g.getChildIndex(target);
tf.text = index.toString();
aroundBehavior(index,1);
Tweener.addTween(e.target, {
scaleX:1, scaleY:1,
time:0.5,
transition:"easeOutCubic"
});
}
private function aroundBehavior(index:int,scale:Number):void{
if(index % 5 != 0){
Tweener.addTween(g.getChildAt(index-1), {scaleX:scale, scaleY:scale,time:0.5,transition:"easeOutCubic"});
}
if(index > 4){
Tweener.addTween(g.getChildAt(index-5), {scaleX:scale, scaleY:scale,time:0.5,transition:"easeOutCubic"});
}
if(index % 5 != 4){
Tweener.addTween(g.getChildAt(index+1), {scaleX:scale, scaleY:scale,time:0.5,transition:"easeOutCubic"});
}
if(index < numOfCircle -5){
Tweener.addTween(g.getChildAt(index+5), {scaleX:scale, scaleY:scale,time:0.5,transition:"easeOutCubic"});
}
}
}
}