flash on 2009-11-9
2009-11-10 複数表示
2009-11-11 挙動を微調整
/**
* Copyright iong ( http://wonderfl.net/user/iong )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/bDXt
*/
/* 2009-11-10 複数表示 */
/* 2009-11-11 挙動を微調整 */
package{
import flash.display.Sprite;
[SWF(width="465", height="465", backgroundColor="#000000", frameRate="30")]
public class FlashTest extends Sprite
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Graphics;
import flash.display.BlendMode;
import flash.filters.BlurFilter;
import flash.display.Stage;
import flash.display.StageScaleMode;
import flash.display.StageQuality;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.utils.setInterval;
import flash.utils.clearInterval;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.Security;
private var cvData:BitmapData;
private var cvB:Bitmap;
private var cv:Sprite;
private var img:Array = new Array();
private var imgNum:uint = 0;
private var prvNum:uint = 0;
private var actTarget:Bitmap;
private var loaderImg:Loader;
private var LC:LoaderContext;
private var imgURL:Array = new Array(
'http://farm3.static.flickr.com/2776/4086665734_9ce15330c7.jpg'
,'http://farm3.static.flickr.com/2689/4085909695_285380b773.jpg'
,'http://farm3.static.flickr.com/2480/4075020210_39e03490f3.jpg'
,'http://farm4.static.flickr.com/3100/2848997160_d109fbc98e.jpg' // test
);
// 画像の自動切り替えspan(秒)
private var intSpan:uint = 6;
private var SIId:uint = 0;
// 分割するサイズ
private var iEW:uint = 10;
private var iEH:uint = 80;
private var cR:Rectangle;
private var spW:uint;
private var spH:uint;
private var iActCnt:uint = 0;
private var iActCntAll:uint = 0;
private var aryAct:Array = new Array();
public function FlashTest():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.quality = StageQuality.LOW;
Security.loadPolicyFile("http://farm3.static.flickr.com/crossdomain.xml");
Security.loadPolicyFile("http://farm4.static.flickr.com/crossdomain.xml");
LC= new LoaderContext(true);
cvData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x000000);
addChild(cvB = new Bitmap(cvData));
cv = new Sprite();
loadImgPiece();
addEventListener(Event.ENTER_FRAME, loadImgGroup);
}
private function loadImgGroup(e:Event):void
{
if(img.length==imgURL.length){
removeEventListener(Event.ENTER_FRAME, loadImgGroup);
SIAutoPlay();
setSI();
}
}
private function loadImgPiece():void
{
loaderImg = new Loader();
loaderImg.contentLoaderInfo.addEventListener(Event.COMPLETE, onLC);
loaderImg.load(new URLRequest(imgURL[img.length]), LC);
}
private function onLC(e:Event):void
{
img.push(initImg(e));
var target:Bitmap = img[(img.length-1)];
target.x += (stage.stageWidth-target.width)/2;
target.y += (stage.stageHeight-target.height)/2;
if(img.length<imgURL.length) loadImgPiece();
}
private function initImg(e:Event):Bitmap
{
var tmpL:LoaderInfo = e.currentTarget as LoaderInfo;
var target:Loader = tmpL.loader;
var imgData:BitmapData = new BitmapData(target.width, target.height);
imgData.draw(target);
return new Bitmap(imgData);
}
private function makeImg():void
{
var tmpAry:Array = new Array();
var iH:uint;
aryAct[iActCnt]= new Array();
for(var i:int=0; i<spH; i++){
tmpAry.push(i);
}
var mi:uint = tmpAry.length;
var flgE:Boolean = false;
for(i=0; i<mi; i++){
var tC:uint = i;
// var tC:uint = Math.round(Math.random()*(tmpAry.length-1));
iH = tmpAry[tC];
var cM:Matrix = new Matrix();
cM.translate(-iEW*iActCnt, -iEH*iH);
var cB:BitmapData= new BitmapData(iEW+1, iEH+1, true, 0x000000);
cB.draw(actTarget, cM, null, null, cR, true);
var efS:Sprite = new Particle(cB, i, actTarget.x+iEW*iActCnt, actTarget.y+iEH*iH);
efS.name = "p"+iActCnt+"_"+i;
efS.alpha = 0;
cv.addChild(efS);
aryAct[iActCnt].push(efS);
// tmpAry.splice(tC, 1);
iActCntAll++;
}
}
// 切り替え
private function chgImg(bmp:Bitmap):void
{
cv = new Sprite();
addChild(cv);
actTarget = bmp;
cR = new Rectangle(0, 0, bmp.width, bmp.height);
spW = Math.ceil(bmp.width/iEW);
spH = Math.ceil(bmp.height/iEH);
removeChild(cvB);
cvData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x000000);
addChild(cvB = new Bitmap(cvData));
iActCnt = 0;
bmp.addEventListener(Event.ENTER_FRAME, chgImgGroup);
}
private function chgImgGroup(e:Event):void
{
if(spW>iActCnt){
if(iActCnt==0){
var prvImg:Bitmap = img[prvNum];
if(getChildByName(prvImg.name)!=null) prvImg.addEventListener(Event.ENTER_FRAME, FOImg);
}
makeImg();
for(var i:int=0; i<aryAct[iActCnt].length; i++){
var target:Sprite = Sprite(cv.getChildByName("p"+iActCnt+"_"+i));
target.addEventListener(Event.ENTER_FRAME, chgImgPiece);
}
iActCnt++;
}else{
if(iActCntAll==0){
e.target.removeEventListener(Event.ENTER_FRAME, chgImgGroup);
removeChild(cv);
addChild(e.target as Bitmap);
}
}
// cvData.draw(cv);
}
private function chgImgPiece(e:Event):void
{
if(e.target.cnt<=0){
e.target.alpha += 0.05;
e.target.x += (e.target.ex-e.target.x)*.2;
if(e.target.alpha>=1 && e.target.x-e.target.ex<0.5){
e.target.alpha = 1;
e.target.x = e.target.ex;
e.target.removeEventListener(Event.ENTER_FRAME, chgImgPiece);
iActCntAll--;
}
}else{
e.target.cnt--;
}
}
private function FOImg(e:Event):void
{
if(e.target.alpha<=0){
e.target.removeEventListener(Event.ENTER_FRAME, FOImg);
removeChild(e.target as Bitmap);
e.target.filters= null;
e.target.alpha=1;
}else{
e.target.alpha -=0.05;
var blNum:uint = Math.round(32-32*e.target.alpha);
var blImg:BlurFilter = new BlurFilter(blNum, blNum);
e.target.filters = [blImg];
}
}
// 自動再生
private function SIAutoPlay():void
{
prvNum = (imgNum-1<0) ? img.length-1: imgNum-1;
var target:Bitmap = img[imgNum];
chgImg(target);
imgNum++; if(imgNum==img.length) imgNum=0;
}
private function setSI():void
{
SIId = setInterval(SIAutoPlay, intSpan*1000);
}
private function clearSI():void
{
clearInterval(SIId);
}
}
}
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
class Particle extends Sprite
{
public var cnt:uint;
public var ex:int;
function Particle(cB:BitmapData, i:uint, x:int, y:int):void
{
addChild(new Bitmap(cB));
this.cnt = i;
this.ex = x;
this.x = this.ex + 100;
this.y = y;
}
}