flashiroha
(88) FLASHフォトビューアー11(as3.0とas2.0の比較)   2009/6/1

as3.0
as2.0

import flash.display.Loader;
import flash.net.URLRequest;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.filters.ColorMatrixFilter;
var picTween:Tween;
var mcTween:Tween;
var pic_mc:MovieClip = new MovieClip();
var picLoader:Loader = new Loader();
var serNum:Array=new Array(9,5,9,5,7);
var serTitle:Array=new Array("滝","径","樹","光","渓");
title_mc.visible=false;
var x0:Number=100;
var y0:Number=150;
var m:Number;
var n:Number;
var total:Number;
var url:String;

//初期設定
defaultSetting();
function defaultSetting():void {
  txtBox.text="";
  next_btn.visible=back_btn.visible=reset_btn.visible=false;
  for (var i:int =1; i<=serNum.length; i++) {
    for (var j:int=1; j<=serNum[i-1]; j++) {
      var p_mc:MovieClip = new MovieClip();
      p_mc.name="p"+i+j;
      addChild(p_mc);
      p_mc.mouseChildren=false;
      p_mc.buttonMode = true;
      loadThumb(p_mc,i,j);
      colorConvert(p_mc,"gray");
      p_mc.sernum=i;
      p_mc.num=j;
      p_mc.addEventListener(MouseEvent.ROLL_OVER, rollover);
      p_mc.addEventListener(MouseEvent.ROLL_OUT, rollout);
      p_mc.addEventListener(MouseEvent.CLICK, passSlide);
    }
  }
}

//サムネイルのロールオーバー効果
function rollover(event:MouseEvent):void {
  var mc:MovieClip=event.target as MovieClip;
  colorConvert(mc,"normal");
  for (var k:int=1; k<=serNum[event.target.sernum-1]; k++) {
    if (k!==event.target.num) {
      mc=MovieClip(getChildByName("p"+event.target.sernum+k));
      colorConvert(mc,"reverse");
    }
  }
}

//サムネイルのロールアウト効果
function rollout(event:MouseEvent):void {
  for (var k:int=1; k<=serNum[event.target.sernum-1]; k++) {
    var mc:MovieClip=MovieClip(getChildByName("p"+event.target.sernum+k));
    colorConvert(mc,"gray");
  }
}

//サムネイルをロードしステージに配置する
function loadThumb(load_mc:MovieClip, ser:Number, n:Number):void {
  var mcLoader:Loader = new Loader();
  load_mc.addChild(mcLoader);
  var url:String="img/p"+ser+n+".jpg";
  var urlReq:URLRequest=new URLRequest(url);
  mcLoader.load(urlReq);
  mcLoader.contentLoaderInfo.addEventListener( Event.COMPLETE , setPos);
  function setPos():void {
    load_mc.w=load_mc.width;
    load_mc.h=load_mc.height;
    load_mc.x=stage.width/2;
    load_mc.y=stage.height/2;
    load_mc.scaleX=load_mc.scaleY=0.1;
    function enterframe() {
      load_mc.x += (x0+80*(n-1)+(80-load_mc.w)/2-load_mc.x)/3;
      load_mc.y += (y0+120*(ser-1)+(80-load_mc.h)/2-load_mc.y)/3;
      load_mc.scaleX += (1-load_mc.scaleX)/3;
      load_mc.scaleY += (1-load_mc.scaleY)/3;
      if (load_mc.scaleX>0.99) {
        title_mc.visible=true;
        load_mc.removeEventListener(Event.ENTER_FRAME, enterframe);
      }
    }
    load_mc.addEventListener(Event.ENTER_FRAME, enterframe);
    mcLoader.contentLoaderInfo.removeEventListener( Event.COMPLETE , setPos);
  }
}

//写真切り替えセッティング
function passSlide(event:MouseEvent):void {
  m=event.target.sernum;
  n=event.target.num;
  total=serNum[m-1];
  urlSetting();
  transferThumb()
  next_btn.visible=back_btn.visible=reset_btn.visible=true;
}

//送り(ネクスト)ボタンで作動
next_btn.addEventListener(MouseEvent.CLICK, forward);
function forward(event:MouseEvent):void {
  if (n==total) {
    n=0;
  }
  n++;
  urlSetting();
  transferThumb()
}

//戻り(バック)ボタンで作動
back_btn.addEventListener(MouseEvent.CLICK, backward);
function backward(event:MouseEvent):void {
  if (n==1) {
    n=total+1;
  }
  n--;
  urlSetting();
  transferThumb()
}

//リセットボタンで作動
reset_btn.addEventListener(MouseEvent.CLICK, reset);
function reset(event:MouseEvent):void {
  removeChild(pic_mc);
  for (var i:int =1; i<=serNum.length; i++) {
    for (var j:int=1; j<=serNum[i-1]; j++) {
      var mc:MovieClip=MovieClip(getChildByName("p"+i+j));
      removeChild(mc);
    }
  }
  defaultSetting();
}

//ロードする拡大写真のファイル名セット、と画面設定
function urlSetting():void {
  url="img/pic"+m+n+".jpg";
  removeThumb();
  txtBox.text=serTitle[m-1]+n;
  loadPic();
}

//拡大写真のロードとフェイドイン配置
function loadPic():void {
  addChild(pic_mc);
  pic_mc.addChild(picLoader);
  var urlReq:URLRequest=new URLRequest(url);
  picLoader.load(urlReq);
  picLoader.contentLoaderInfo.addEventListener( Event.COMPLETE , displayPic);
  function displayPic():void {
    var Lw:Number=pic_mc.width;
    var Lh:Number=pic_mc.height;
    pic_mc.x = 25+(400-Lw/2);
    pic_mc.y = 25+(400-Lh/2);
    picTween=new Tween(pic_mc,"alpha",None.easeInOut,0,1,5,false);
    picLoader.removeEventListener( Event.COMPLETE , displayPic);
  }
}





//サムネイル(ターゲットシリーズ外)の非表示化
function removeThumb():void {
  title_mc.visible=false;
  for (var i:int=1; i<=serNum.length; i++) {
    if (i!==m) {
      for (var j:int=1; j<=serNum[i-1]; j++) {
        var mc:MovieClip=MovieClip(getChildByName("p"+i+j));
        mc.visible=false;
      }
    }
  }
}

//サムネイル(ターゲットシリーズの)移動
function transferThumb():void {
  var n_mc=MovieClip(getChildByName("p"+m+n));
  var w=n_mc.width;
  for (var i:int=1; i<=total; i++) {
    var mc=MovieClip(getChildByName("p"+m+i));
    mc.scaleX=mc.scaleY=0.8;
    if (w>=60) {
      mc.x =120+75*(i-1);
      mc.y=760;
    } else {
      mc.x=760;
      mc.y = 80+70*(i-1);
    }
    mcTween=new Tween(mc,"alpha",None.easeInOut,0,1,5,false);
  }
}


//サムネイル表示色の変換
function colorConvert(image:MovieClip, colorMode:String):void {
  if (colorMode=="normal") {
    var matrix:Array=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];
  } else if (colorMode == "gray") {
    matrix=[0.3,0.59,0.11,0,0,0.3,0.59,0.11,0,0,0.3,0.59,0.11,0,0,0,0,0,1,0];
  } else {
    matrix=[0,0,1,0,0,0,1,0,0,0,0.25,1,0,0,0,0,0,0,1,0];
  }
  var colorFilter:ColorMatrixFilter=new ColorMatrixFilter(matrix);
  image.filters=[colorFilter];
}

import flash.filters.ColorMatrixFilter;
var serNum = [9, 5, 9, 5, 7];
var serTitle = ["滝", "径", "樹", "光", "渓"];
title_mc._visible = false;
x0 = 100;
y0 = 150;
var m:Number;
var n:Number;
var total:Number;
var url:String;









defaultSetting();
function defaultSetting() {
  txtBox.text = "";
  next_btn._visible = back_btn._visible=reset_btn._visible=false;
  var pic_mc = this.createEmptyMovieClip("pic_mc", 100);
  for (i=1; i<=serNum.length; i++) {
    for (j=1; j<=serNum[i-1]; j++) {
      p_mc = this.createEmptyMovieClip("p_mc"+i+j, 10*i+j);
      p_mc.createEmptyMovieClip("ps",10*i+j);
      loadThumb(p_mc.ps,i,j);
      colorConvert(p_mc,"gray");
      p_mc.sernum = i;
      p_mc.num = j;
      p_mc.onRollOver = rollover;
      p_mc.onRollOut = rollout;
      p_mc.onRelease = passSlide;
    }
  }
}



function rollover() {
  colorConvert(this,"normal");
  for (k=1; k<=serNum[this.sernum-1]; k++) {
    if (k !== this.num) {
      colorConvert(_root["p_mc"+this.sernum+k],"reverse");
    }
  }
}





function rollout() {
  for (k=1; k<=serNum[this.sernum-1]; k++) {
    colorConvert(_root["p_mc"+this.sernum+k],"gray");
  }
}


function loadThumb(load_mc,m,n) {
  var mcLoader:MovieClipLoader = new MovieClipLoader();
  jpg = "img/p"+m+n+".jpg";
  mcLoader.loadClip(jpg,load_mc);
  var oListener:Object = new Object();
  oListener.onLoadInit = function() {
    load_mc.w = load_mc._width;
    load_mc.h = load_mc._height;
    load_mc._x = Stage.width/2;
    load_mc._y = Stage.height/2;
    load_mc._xscale = load_mc._yscale=10;
    load_mc.onEnterFrame = function() {
      this._x += (x0+80*(n-1)+(80-this.w)/2-this._x)/3;
      this._y += (y0+120*(m-1)+(80-this.h)/2-this._y)/3;
      this._xscale += (100-this._xscale)/3;
      this._yscale += (100-this._yscale)/3;
      if (this._xscale>98) {
        if (this == p_mc56.ps) {
          title_mc._visible = true;
        }
        delete this.onEnterFrame;
      }
    };
  };
  mcLoader.addListener(oListener);
}





function passSlide() {
  m = this.sernum;
  n = this.num;
  total = serNum[m-1];
  urlSetting();
  transferThumb();
  next_btn._visible = back_btn._visible=reset_btn._visible=true;
}

next_btn.onRelease = function() {
  if (n == total) {
    n = 0;
  }
  n++;
  urlSetting();
  transferThumb();
}


back_btn.onRelease = function() {
  if (n == 1) {
    n = total+1;
  }
  n--;
  urlSetting();
  transferThumb();
};


reset_btn.onRelease = function() {
  pic_mc.removeMovieClip();
  defaultSetting();
};








function urlSetting() {
  url = "img/pic"+m+n+".jpg";
  loadPic();
  removeThumb();
  txtBox.text = serTitle[m-1]+n;
}

function loadPic() {
  var picLoader:MovieClipLoader = new MovieClipLoader();
  picLoader.loadClip(url,pic_mc);
  var pListener:Object = new Object();
  pListener.onLoadInit = function() {
    Lw = pic_mc._width;
    Lh = pic_mc._height;
    pic_mc._alpha = 0;
    pic_mc._x = 25+(400-Lw/2);
    pic_mc._y = 25+(400-Lh/2);
    pic_mc.onEnterFrame = function() {
      this._alpha += (100-this._alpha)/10;
      if (this._alpha>95) {
        this._alpha = 100;
        delete this.onEnterFrame;
      }
    };
  };
  picLoader.addListener(pListener);
}

function removeThumb() {
  title_mc._visible = false;
  for (i=1; i<=serNum.length; i++) {
    if (i !== m) {
      for (j=1; j<=serNum[i-1]; j++) {
        this["p_mc"+i+j]._visible = false;
      }
    }
  }
}


function transferThumb() {
  w = _root["p_mc"+m+n].ps._width;
  for (i=1; i<=total; i++) {
    p_mc = this["p_mc"+m+i].ps;
    p_mc._alpha = 0;
    if (w>=60) {
      p_mc._x = 120+75*(i-1);
      p_mc._y = 760;
    } else {
      p_mc._x = 760;
      p_mc._y = 80+70*(i-1);
    }
    p_mc.onEnterFrame = function() {
      this._xscale = this._yscale=80;
      this._alpha += (100-this._alpha)/5;
    };
  }
}
function colorConvert(image, colorMode) {
  if (colorMode == "normal") {
    var matrix:Array =[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];
  } else if (colorMode == "gray") {
   matrix=[0.3,0.59,0.11,0,0,0.3,0.59,0.11,0,0,0.3,0.59,0.11,0,0,0,0,0,1,0];
  } else {
    matrix=[0,0,1,0,0,0,1,0,0,0,0.25,1,0,0,0,0,0,0,1,0];
}
  var colorFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
  image.filters = [colorFilter];
}

   
 
flashirohaサイト内  Web全体