iPhone的なページめくり、、をしたい
iPhone的なページめくり SIHO
でも、ページがフィックスする部分がダサい
/**
* Copyright SIHO ( http://wonderfl.net/user/SIHO )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vyY2
*/
package {
/*iPhone的なページめくり SIHO*/
/*でも、ページがフィックスする部分がダサい*/
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.text.TextField;
[SWF(stageWidth = 320,stageHeight = 480,frameRate = "24")]
public class FlashTest extends Sprite {
private var mc:MovieClip = new MovieClip();
private var sp1:Sprite = new Sprite();
private var sp2:Sprite = new Sprite();
private var sp3:Sprite = new Sprite();
private var pointX:Number;
private var outPutfld:TextField =new TextField();
private var nowPage:uint = 1;
private var lastPage:uint = 3;
private var targetSp:Object;
public function FlashTest() {
outPutfld.text= "hoge";
addChild(outPutfld);
mc.name = "mc";
addChild(mc);
sp1.graphics.beginFill(0x3299ff);
sp1.graphics.drawRect(0,30,stage.stageWidth,450);
sp1.graphics.endFill();
sp1.name = "1";
mc.addChild(sp1);
sp2.graphics.beginFill(0x6699ff);
sp2.graphics.drawRect(stage.stageWidth,30,stage.stageWidth,450);
sp2.graphics.endFill();
sp2.name = "2";
mc.addChild(sp2);
sp3.graphics.beginFill(0x9966ff);
sp3.graphics.drawRect(stage.stageWidth*2,30,stage.stageWidth,450);
sp3.graphics.endFill();
sp3.name = "3";
mc.addChild(sp3);
mc.addEventListener(MouseEvent.MOUSE_DOWN , onDown);
stage.addEventListener(MouseEvent.MOUSE_UP , onUp);
}
private function onDown(event:MouseEvent):void{
targetSp = event.currentTarget;
nowPage = event.target.name;
pointX= mouseX;
stage.addEventListener(MouseEvent.MOUSE_MOVE , onMove);
}
private function onUp(event:MouseEvent):void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE , onMove);
switch (nowPage) {
case 1://最初のページのとき
if (targetSp.x < -stage.stageWidth / 2) {
targetSp.x = -stage.stageWidth;
nowPage += 1;
}else targetSp.x = 0;
break;
case lastPage ://最後のページのとき
if (targetSp.x > -stage.stageWidth / 2 - (stage.stageWidth*(nowPage-2))) {
targetSp.x = -stage.stageWidth*(nowPage-2);
nowPage -= 1;
}else if (targetSp.x < -(stage.stageWidth / 2 + stage.stageWidth*(nowPage-1))) {
targetSp.x = -stage.stageWidth*(nowPage-1);
}else targetSp.x = -stage.stageWidth*(nowPage-1);
break;
default:
if (targetSp.x > -stage.stageWidth / 2 - (stage.stageWidth*(nowPage-2))) {
targetSp.x = -stage.stageWidth*(nowPage-2);
nowPage -= 1;
}else if (targetSp.x < -(stage.stageWidth / 2 + stage.stageWidth*(nowPage-1))) {
targetSp.x = -stage.stageWidth*nowPage;
nowPage += 1;
}else targetSp.x = -stage.stageWidth*(nowPage-1);
}
outPutfld.text = String(nowPage);
}
private function onMove(event:MouseEvent):void {
mc.x += (mouseX-pointX)*0.05
}
}
}