forked from: forked from: iPhone的なページめくり、、をしたい
iPhone的なページめくり SIHO
でも、ページがフィックスする部分がダサい
とりいそぎTween入れてフレームレート上げてみました。
/**
* Copyright nayu ( http://wonderfl.net/user/nayu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/35uS
*/
// forked from ish_xxxx's forked from: iPhone的なページめくり、、をしたい
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)]
import flash.accessibility.Accessibility;
public class FlashTest extends Sprite
{
private var mc:MovieClip = new MovieClip();
private var sp0:Sprite = new Sprite();
private var sp1:Sprite = new Sprite();
private var sp2: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= "改造";
addChild(outPutfld);
this.mc.name = "mc";
addChild(mc);
for(var i:int = 0; i < 5; i++)
{
var spName:Sprite = new Sprite();
var color:int = Number("0x" + i*9999);
spName.graphics.beginFill(color);
spName.graphics.drawRect(stage.stageWidth * i,30,stage.stageWidth - 50,450 - 50);
spName.graphics.endFill();
spName.name = String(i);
this.mc.addChild(spName);
}
this.mc.addEventListener(MouseEvent.MOUSE_DOWN , onDown);
stage.addEventListener(MouseEvent.MOUSE_UP , onUp);
}
private function onDown(event:MouseEvent):void
{
this.targetSp = event.currentTarget;
this.nowPage = event.target.name;
this.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;
var nowPage:int = Number(event.target.name);
switch(nowPage)
{
case 0:
if(this.targetSp.x < -stage.stageWidth / 2)
{
tx = -stage.stageWidth;
nowPage += 1;
}
else
{
tx = 0;
}
break;
default:
break;
}
/*
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
}
}
}
import flash.text.TextField;
class test
{
private var mytxt:TextField = new TextField();
}