モザイクでフェードイン/フェードアウト
モザイクフェードアウト→入替→モザイクフェードイン
の繰り返し。
package {
import flash.display.Sprite;
import flash.events.Event;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="60")]
/**
* モザイクフェードアウト→入替→モザイクフェードイン
* の繰り返し。
*/
public class fadeMosaic_ver1 extends Sprite
{
private var Layer_a:Sprite = new Sprite();
private var Layer_b:Sprite = new Sprite();
private var mosaicMC:mosaicFader;
private var W:Number = 465;
private var H:Number = 465;
//private var W:Number = 900;
//private var H:Number = 450;
private var mosCounter:uint = 0;
public function fadeMosaic_ver1()
{
addChildAt(Layer_a,0);
addChildAt(Layer_b,1);
setImg();
setMosaicLayer();
mosaicMC.addEventListener("mosaicComp", mosaicCompHandler);
mosaicMC.mosaicFromTo(1,50,Layer_a, 2, 1);
}
private function mosaicCompHandler(e:Event):void
{
trace("mosaicComp");
if(mosCounter%2==1){
mosaicMC.mosaicFromTo(1,50,Layer_a, 2, 2);
} else {
mosaicMC.mosaicFromTo(50,1,Layer_a, 2, 0);
setImg();
}
mosCounter++;
}
private function setImg():void
{
Layer_a.graphics.clear();
for( var i:uint=0; i<10; i++ )
{
Layer_a.graphics.beginFill(0xffffff);
Layer_a.graphics.drawCircle(W*Math.random(),H*Math.random(),50*Math.random());
Layer_a.graphics.endFill();
}
}
private function setMosaicLayer():void
{
mosaicMC = new mosaicFader(W, H)
Layer_b.addChild( mosaicMC );
mosaicMC.x = W / 2;
mosaicMC.y = H / 2;
}
}
}
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Matrix;
import caurina.transitions.Tweener;
import flash.events.Event;
class mosaicFader extends Sprite
{
private var bmp:Bitmap;
private var bmpData:BitmapData;
private var Mtx:Matrix;
private var W:Number, H:Number;
public var scaleNum:uint = 10; //モザイクの拡大率
public function mosaicFader(pw:Number, ph:Number)
{
W = pw;
H = ph;
bmpData = new BitmapData(1,1);
bmp = new Bitmap(bmpData);
addChild(bmp);
bmp.x = -W / 2;
bmp.y = -H / 2;
}
public function setMosaic(mc:Sprite):void
{
Mtx = new Matrix();
Mtx.scale( 1/scaleNum, 1/scaleNum );
bmpData = new BitmapData( W/scaleNum, H/scaleNum, false, 0x000000 );
bmpData.draw( mc, Mtx );
bmp.bitmapData = bmpData;
bmp.scaleX = W/bmpData.width;
bmp.scaleY = H/bmpData.height;
}
public function mosaicFromTo(n1:uint, n2:uint, mc:Sprite, t:Number, d:Number):void
{
scaleNum = n1;
Tweener.addTween(this, {time:t, scaleNum:n2, onUpdate:setMosaic, onUpdateParams:[mc],
transition:"linear", onComplete:mosaicComplete, delay:d});
}
private function mosaicComplete():void
{
dispatchEvent(new Event("mosaicComp"));
}
}