スライドモドキ
はじめてちゃんとas3.0で組んでみました…
未だに多くの部分が意味不明
/**
* Copyright youyokoi ( http://wonderfl.net/user/youyokoi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7hM1
*/
package
{
import flash.display.*;
import flash.events.Event;
import flash.text.*;
import frocessing.display.F5CanvasMovieClip2D;
import frocessing.display.F5MovieClip2D;
import frocessing.color.*;
import flash.utils.getDefinitionByName;
import flash.events.MouseEvent;
import caurina.transitions.Tweener;
[SWF(width=800,height=600,backgroundColor=0xCCCCCC,frameRate=60)]
/**
* ...
* @author TEST
*/
public class Main extends Sprite
{
public var leftNavi:F5MovieClip2D;
public var rightNavi:F5MovieClip2D;
public var naviBoxW:Number = 100;
public var photoBox:F5MovieClip2D;
public var photoBoxArr:Array = [];
public var photoBox_defX:Number = 0;
public var photoBox_defY:Number = 0;
public var photoBox_defW:Number = 400;
public var photoBox_defH:Number = 400;
public var photoBox_defAlpha:Number = 1;
public var BoxNum:Number;
public var NowBoxNum:Number = 0;
public var PosX:Number;
public var PosY:Number;
public var maxX:Number = stage.stageWidth; //stageのx位置max
public var minX:Number = 0 - photoBox_defW;
public var maxY:Number = stage.stageHeight; //stageのx位置max
public var miny:Number = 0-photoBox_defH;
public var leftNaviBox_txt:TextField;
public var rightNaviBox_txt:TextField;
public var naviBox_tf:TextFormat;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
//leftNavi BOX 作成
leftNavi = new F5MovieClip2D();
leftNavi.fill(0,0,0);
leftNavi.noStroke();
leftNavi.rect(0, 0, naviBoxW, stage.stageHeight);
leftNavi.buttonMode = true;
addChild(leftNavi);
//rightNavi BOX 作成
rightNavi = new F5MovieClip2D();
rightNavi.fill(0,0,0);
rightNavi.noStroke();
rightNavi.rect(0, 0, naviBoxW, stage.stageHeight);
rightNavi.x = stage.stageWidth - naviBoxW;
rightNavi.buttonMode = true;
addChild(rightNavi);
rightNavi.alpha = leftNavi.alpha = 0.7;
//テキストフォーマット
naviBox_tf = new TextFormat();
naviBox_tf.color = 0xFFFFFF;
naviBox_tf.font = "Times New Roman";
naviBox_tf.size = 40;
naviBox_tf.kerning = false;
// <
leftNaviBox_txt = new TextField();
leftNavi.addChildAt(leftNaviBox_txt,1);
leftNaviBox_txt.text = "<";
leftNaviBox_txt.setTextFormat(naviBox_tf);
leftNaviBox_txt.x = leftNavi.width / 2 - leftNaviBox_txt.textWidth/2;
leftNaviBox_txt.y = leftNavi.height / 2 - leftNaviBox_txt.textHeight / 2;
// >
rightNaviBox_txt = new TextField();
rightNavi.addChildAt(rightNaviBox_txt,1);
rightNaviBox_txt.text = ">";
rightNaviBox_txt.setTextFormat(naviBox_tf);
rightNaviBox_txt.x = (rightNavi.width / 2 - rightNaviBox_txt.textWidth/2);
rightNaviBox_txt.y = rightNavi.height / 2 - rightNaviBox_txt.textHeight / 2;
// photo box 生成
NowBoxNum = 0;
addphotoBox(0, maxX / 2 - photoBox_defW / 2, maxY / 2 - photoBox_defH / 2,1);
addphotoBox(1, maxX, stage.height / 2 - photoBox_defH / 2,0);
addphotoBox(-1, (-photoBox_defW), stage.height / 2 - photoBox_defH / 2,0);
//
addmouseEvent();
}
private function reset_func(e:Event):void{
photoBoxArr[0].x = photoBox_defX;
photoBoxArr[0].y = photoBox_defY;
photoBoxArr[0].alpha = photoBox_defAlpha;
}
private function rightBox(e:MouseEvent):void {
//現在表示しているBoxの座標を記憶
PosX = photoBoxArr[NowBoxNum].x;
PosY = photoBoxArr[NowBoxNum].y;
delphotoBox(NowBoxNum + 1);
tweeHandler(NowBoxNum, maxX, maxY / 2 - photoBox_defH / 2, "del");
tweeHandler(NowBoxNum -1, PosX, PosY,"ido");
NowBoxNum = NowBoxNum - 1;
//Box生成
addphotoBox(NowBoxNum - 1, -photoBox_defW, maxY / 2 - photoBox_defH / 2,0);
trace("NowBoxNum=" + NowBoxNum);
}
private function leftBox(event:MouseEvent):void {
//現在表示しているBoxの座標を記憶
PosX = photoBoxArr[NowBoxNum].x;
PosY = photoBoxArr[NowBoxNum].y;
delphotoBox(NowBoxNum - 1);
tweeHandler(NowBoxNum, minX, maxY / 2 - photoBox_defH / 2, "del");
tweeHandler(NowBoxNum +1, PosX, PosY,"ido");
NowBoxNum = NowBoxNum + 1;
//Box生成
addphotoBox(NowBoxNum + 1, maxX, maxY / 2 - photoBox_defH / 2,0);
trace("NowBoxNum=" + NowBoxNum);
}
//func Box 生成
private function addphotoBox(BoxNum:Number,PosX:Number,PosY:Number,Alpha:Number):void {
photoBox = photoBoxArr[BoxNum] = new F5MovieClip2D();
photoBox.fill(2,0,0);
photoBox.noStroke();
photoBox.rect(0, 0, photoBox_defW, photoBox_defH);
addChild(photoBox);
photoBoxArr[BoxNum].x = PosX;
photoBoxArr[BoxNum].y = PosY;
photoBoxArr[BoxNum].alpha = Alpha;
var BoxNumtxt:TextField = new TextField();
photoBoxArr[BoxNum].addChildAt(BoxNumtxt,1);
BoxNumtxt.text = "No." + Number(BoxNum);
BoxNumtxt.setTextFormat(naviBox_tf);
}
private function delphotoBox(BoxNum:Number):void{
removeChild(photoBoxArr[BoxNum]);
}
private function addmouseEvent():void {
leftNavi.addEventListener(MouseEvent.MOUSE_DOWN,leftBox);
rightNavi.addEventListener(MouseEvent.MOUSE_DOWN,rightBox);
}
private function tweeHandler(BoxNum:Number, Xti:Number, Yti:Number,hoge:String):void {
leftNavi.removeEventListener(MouseEvent.MOUSE_DOWN,leftBox);
rightNavi.removeEventListener(MouseEvent.MOUSE_DOWN,rightBox);
switch(true) {
case hoge == "ido":
Tweener.addTween(photoBoxArr[BoxNum], {
x:Xti,
y:Yti,
alpha:1,
time:1,
transition:"easeInQuad",
onComplete:addmouseEvent//,
//onCompleteParams:[]
});
break;
case hoge == "del":
Tweener.addTween(photoBoxArr[BoxNum], {
x:Xti,
y:Yti,
alpha:0,
time:1,
transition:"easeInQuad",
onComplete:addmouseEvent//,
//onCompleteParams:[]
});
break;
}
}
}
}