/**
* Copyright kawamura ( http://wonderfl.net/user/kawamura )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kW0l
*/
package{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
[SWF(backgroundColor="#000000")]
public class FlashTest extends Sprite{
private var now:uint=0;
private var btns_ar:Array=new Array(14,16,8,7)
public var w:Number;
public var h:Number;
private var flag:Boolean=true;
private var pages_mc:MovieClip;
private var drag_zone:Sprite;
//
private var k:Number=0.3
private var t:Number=0.75;
private var vx:Number=0;
private var ax:Number=0;
private var prex:Number=0;
//
private var app_speed:Number=0.5;
private var move_speed:Number=0.4;
private var open_flag:Boolean=true;
private var pages_ar:Array;
private var app_mc:MovieClip
public function FlashTest():void{
pages_ar=new Array();
//
w=stage.stageWidth;
h=stage.stageHeight;
var i:uint;
var ii:uint;
pages_mc=new MovieClip();
addChild(pages_mc);
drag_zone=new Sprite();
var dzg:Graphics=drag_zone.graphics;
dzg.beginFill(0xFFFFFF);
dzg.drawRect(0,0,btns_ar.length*w,h);
pages_mc.addChild(drag_zone);
addEventListener(Event.ENTER_FRAME,ent);
for(i=0;i<btns_ar.length;i++){
var page_mc:Card=new Card(w,h,i,btns_ar[i]);
pages_mc.addChild(page_mc);
page_mc.x=w*i
pages_ar.push(page_mc)
var _ar:Array=page_mc.btns;
for(ii=0;ii<_ar.length;ii++){
var btn:MovieClip=_ar[ii];
btn.sx=
btn.lx=btn.x;
btn.sy=
btn.ly=btn.y;
btn.addEventListener(Event.ENTER_FRAME,btn_ent)
btn.buttonMode=true;
btn.addEventListener(MouseEvent.CLICK,btn_clk);
btn.addEventListener(MouseEvent.MOUSE_DOWN,btn_mdwn);
}
page_mc.mouseEnabled=false;
}
drag_zone.buttonMode=true;
drag_zone.addEventListener(MouseEvent.MOUSE_DOWN,mdwn);
//
app_mc=new MovieClip();
addChild(app_mc);
var app_g:Graphics=app_mc.graphics;
app_g.beginFill(0x00);
app_g.drawRect(-w*.5,-h*.5,w,h)
app_mc.x=w*0.5;
app_mc.y=h*0.5;
app_mc.scaleX=0
app_mc.lx=0;
app_mc.scaleY=0;
app_mc.ly=0;
app_mc.addEventListener(Event.ENTER_FRAME,app_ent);
app_mc.addEventListener(MouseEvent.CLICK,app_clk)
}
//
private function btn_clk(evt:MouseEvent):void{
btnMove();
var _mc:MovieClip=evt.currentTarget as MovieClip;
_mc.alpha=1;
_mc.removeEventListener(MouseEvent.MOUSE_MOVE,btn_mv)
}
private function btn_mdwn(evt:MouseEvent):void{
var _mc:MovieClip=evt.currentTarget as MovieClip;
_mc.alpha=0.5;
_mc.startX=mouseX;
_mc.startY=mouseY;
_mc.addEventListener(MouseEvent.MOUSE_MOVE,btn_mv);
_mc.addEventListener(MouseEvent.MOUSE_OUT,btn_mout);
}
private function btn_mout(evt:MouseEvent):void{
var _mc:MovieClip=evt.currentTarget as MovieClip;
_mc.alpha=1;
_mc.removeEventListener(MouseEvent.MOUSE_MOVE,btn_mv);
_mc.removeEventListener(MouseEvent.MOUSE_OUT,btn_mout);
startPage();
}
private function btn_mv(evt:MouseEvent):void{
var _mc:MovieClip=evt.currentTarget as MovieClip;
var d:Number=Math.sqrt(Math.pow(mouseX-_mc.startX,2)+Math.pow(mouseY-_mc.startY,2));
if(d>10){
_mc.mouseEnabled=false;
_mc.alpha=1;
_mc.removeEventListener(MouseEvent.MOUSE_MOVE,btn_mv);
_mc.removeEventListener(MouseEvent.MOUSE_OUT,btn_mout);
startPage();
}
}
//
private function mdwn(evt:Event):void{
startPage();
}
private function startPage():void{
flag=false;
//
pages_mc.startDrag(false,new Rectangle(0.5*w,0,-1*btns_ar.length*w,0));
stage.addEventListener(MouseEvent.MOUSE_UP,mup);
}
private function mup(evt:MouseEvent):void{
checkPage();
}
private function checkPage():void{
var i:uint;
var ii:uint;
for(i=0;i<pages_ar.length;i++){
var _ar:Array=pages_ar[i].btns;
for(ii=0;ii<_ar.length;ii++){
var b_mc:MovieClip=_ar[ii];
b_mc.mouseEnabled=true;
}
}
vx=mouseX-prex;
//
flag=true;
//
now=Math.round((-pages_mc.x)/w);
if(now==btns_ar.length)now=btns_ar.length-1;
pages_mc.stopDrag();
//
stage.removeEventListener(MouseEvent.MOUSE_UP,mup)
}
private function ent(evt:Event):void{
if(flag){
var lx:Number=now*-w;
ax=-1*k*(pages_mc.x-lx)-(t)*vx;
vx+=ax
pages_mc.x+=vx;
}else{
if(mouseX>w || mouseX<0){
checkPage();
}
}
prex=mouseX;
}
private function btn_ent(evt:Event):void{
var _mc:MovieClip=evt.currentTarget as MovieClip;
var dx:Number=_mc.lx-_mc.x;
var dy:Number=_mc.ly-_mc.y;
_mc.x+=dx*move_speed;
_mc.y+=dy*move_speed;
}
private function btnMove():void{
var _mc:MovieClip
var i:uint;
var btns_ar:Array=pages_ar[now].btns;
if(open_flag){
open_flag=false;
var scx:Number=w*0.5;
var scy:Number=h*0.5;
for(i=0;i<btns_ar.length;i++){
_mc=btns_ar[i];
var theta:Number=Math.atan2(_mc.ly-scy,_mc.lx-scx);
var dxy:Number=Math.sqrt(Math.pow(_mc.x-scx,2)+Math.pow(_mc.y-scy,2));
_mc.lx=scx+(2*scx+dxy)*Math.cos(theta);
_mc.ly=scy+(2*scy+dxy)*Math.sin(theta);
}
app_mc.lx=1;
app_mc.ly=1;
}else{
open_flag=true;
for(i=0;i<btns_ar.length;i++){
_mc=btns_ar[i];
_mc.lx=_mc.sx;
_mc.ly=_mc.sy;
}
app_mc.lx=0;
app_mc.ly=0;
}
}
//
private function app_clk(evt:MouseEvent):void{
btnMove()
}
private function app_ent(evt:Event):void{
var _mc:MovieClip=evt.currentTarget as MovieClip
var dx:Number=_mc.lx-_mc.scaleX;
var dy:Number=_mc.ly-_mc.scaleY;
_mc.scaleX+=dx*app_speed;
_mc.scaleY+=dy*app_speed;
}
}
}
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.geom.Rectangle;
import flash.display.BlendMode;
class Card extends MovieClip{
private var btns_ar:Array;
private var btn_mc:MovieClip;
private var bg_mc:MovieClip
public function Card(w:Number,h:Number,page_cnt:uint,num:uint):void{
var m_x:Number=40;
var m_y:Number=25;
var dx:Number=(w-50-(2*m_x))/3;
var dy:Number=(h-50-(2*m_y))/3;
btns_ar=new Array()
bg_mc=new MovieClip();
addChild(bg_mc);
var i:uint;
for(i=0;i<num;i++){
btn_mc=new MovieClip();
btn_mc.numb=i
var cg:Graphics=btn_mc.graphics;
cg.beginFill(0xFF0000)
cg.drawRoundRect(-25,-25,50,50,10,10);
btn_mc.x=25+m_x+dx*(i%4);
btn_mc.y=25+m_y+dy*Math.floor(i/4);
addChild(btn_mc);
//
btns_ar.push(btn_mc);
}
//
var txt_txt:TextField=new TextField();
//
var format:TextFormat=new TextFormat();
format.color=0xCCCCCC;
format.size=144;
format.align = TextFormatAlign.CENTER;
format.font="_ゴシック"
//
txt_txt.defaultTextFormat = format;
txt_txt.text=String(page_cnt+1);
//
txt_txt.width=txt_txt.textWidth
txt_txt.height=txt_txt.textHeight
txt_txt.x=w*0.5-txt_txt.width*0.5;
txt_txt.y=h*0.5-txt_txt.height*0.5;
txt_txt.selectable=false;
txt_txt.mouseEnabled=false;
//
bg_mc.addChild(txt_txt)
//
bg_mc.mouseEnabled=false
}
public function get btns():Array{
return btns_ar;
}
public function get bg():MovieClip{
return bg_mc;
}
}