In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: iPhone的なページめくり、、をしたい

iPhone的なページめくり SIHO
でも、ページがフィックスする部分がダサい
とりいそぎTween入れてフレームレート上げてみました。
/**
 * Copyright ish_xxxx ( http://wonderfl.net/user/ish_xxxx )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pD7u
 */

package {
	/*iPhone的なページめくり SIHO*/
	/*でも、ページがフィックスする部分がダサい*/
	/*とりいそぎTween入れてフレームレート上げてみました。*/
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.display.MovieClip;
    import flash.text.TextField;
	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.Back;
	import org.libspark.betweenas3.tweens.ITween;
    
    [SWF(stageWidth = 320,stageHeight = 480,frameRate = 50)]
    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);
			
			//Tween用のパラメータ
			var tx:Number = 0;
			var time:Number = 0.75;
			
			switch (nowPage) {
				case 1://最初のページのとき
				if (targetSp.x < -stage.stageWidth / 2)  {
					//targetSp.x = -stage.stageWidth;
					tx = -stage.stageWidth;
					nowPage += 1;
				}else tx = 0;
				break;
				case lastPage ://最後のページのとき
				if (targetSp.x > -stage.stageWidth / 2 - (stage.stageWidth*(nowPage-2))) {
					//targetSp.x = -stage.stageWidth * (nowPage-2);
					tx = -stage.stageWidth * (nowPage-2);
					nowPage -= 1;
				}else if (targetSp.x < -(stage.stageWidth / 2 + stage.stageWidth*(nowPage-1)))  {
					//targetSp.x = -stage.stageWidth * (nowPage-1);
					tx = -stage.stageWidth * (nowPage-1);
				}else tx = -stage.stageWidth*(nowPage-1);
				break;
				default:
				if (targetSp.x > -stage.stageWidth / 2 - (stage.stageWidth*(nowPage-2))) {
					//targetSp.x = -stage.stageWidth * (nowPage-2);
					tx = -stage.stageWidth * (nowPage-2);
					nowPage -= 1;
				}else if (targetSp.x < -(stage.stageWidth / 2 + stage.stageWidth*(nowPage-1)))  {
					//targetSp.x = -stage.stageWidth * nowPage;
					tx = -stage.stageWidth * nowPage;
					nowPage += 1;
				}else tx = -stage.stageWidth * (nowPage-1);
				
			}
			
			//Tween
			BetweenAS3.to(
				targetSp
				,
				{
					x: tx
				}
				,
				time
				,
				Back.easeOut
			).play();
			
			outPutfld.text = String(nowPage);
		}
			
		private function onMove(event:MouseEvent):void {
			mc.x += (mouseX-pointX)*0.05
		}
    }
}