Skip to content

Instantly share code, notes, and snippets.

@Tomyail
Last active December 10, 2015 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tomyail/4508363 to your computer and use it in GitHub Desktop.
Save Tomyail/4508363 to your computer and use it in GitHub Desktop.
package
{
import com.greensock.TweenLite;
import com.greensock.easing.Quad;
import com.greensock.easing.Quart;
import com.greensock.easing.Quint;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class CircularCoverFlow extends Sprite
{
private static const GAP:int = 60;
private static const LEFT_BUFF:int = 2;
private static const TWEEN_FUN:Function = Quart.easeInOut
private static const TWEEN_TIME:Number = 0.3;
private static const VISUAL_NUMBER:int = 3;
public function CircularCoverFlow()
{
preBtn = createBtn(10, 20);
nextBtn = createBtn(30, 20);
addChild(preBtn);
addChild(nextBtn);
preBtn.addEventListener(MouseEvent.CLICK, buttonClick);
nextBtn.addEventListener(MouseEvent.CLICK, buttonClick);
create(10);
var border:Sprite = new Sprite();
border.graphics.lineStyle(1);
border.graphics.drawRect(0, 0, 3 * 60, 60);
border.y = 100;
addChild(border);
}
private const NEXT:String = "next";
private const PRE:String = "pre";
private var boxes:Vector.<Box>;
private var current:int;
private var currentDirect:String = NEXT;
private var nextBtn:Sprite;
private var preBtn:Sprite;
public function anim():void
{
// setChildIndex(boxes[current],this.numChildren-1);
var pt:Node = boxes[current].node;
var cNode:Node = pt;
var temp:int = pt.data.x;
while (cNode[currentDirect] != pt)
{
TweenLite.to(cNode.data.box, TWEEN_TIME, { x: cNode[currentDirect].data.x, ease: TWEEN_FUN });
cNode.data.x = cNode[currentDirect].data.x;
cNode = cNode[currentDirect];
}
cNode.data.x = temp;
TweenLite.to(cNode.data.box, TWEEN_TIME, { x: temp, ease: TWEEN_FUN });
trace(current);
}
//Button actions
protected function buttonClick(evt:MouseEvent):void
{
if (evt.target == preBtn)
{
currentDirect = NEXT;
current = (--current % boxes.length + boxes.length) % boxes.length
}
else
{
currentDirect = PRE;
current = (++current % boxes.length + boxes.length) % boxes.length
}
anim();
}
private function create(itemNum:int):void
{
//crate box
boxes = new Vector.<Box>();
for (var i:int = 0; i < itemNum; i++)
{
boxes[i] = new Box(i);
addChild(boxes[i]);
boxes[i].y = 100;
}
//create data(modify to fit your own request)
for (i = 0; i < itemNum; i++)
{
if (i < itemNum - LEFT_BUFF)
{
boxes[i].node.data.x = GAP * i;
}
//pos left buff
else
{
boxes[i].node.data.x = (i - boxes.length) * GAP;
}
}
//build node
for (i = 0; i < itemNum - 1; i++)
{
boxes[i].node.next = boxes[i + 1].node;
boxes[i + 1].node.pre = boxes[i].node;
}
boxes[0].node.pre = boxes[boxes.length - 1].node;
boxes[boxes.length - 1].node.next = boxes[0].node;
//run
anim();
}
private function createBtn(x:int, y:int):Sprite
{
var s:Sprite = new Sprite();
s.graphics.beginFill(0xff);
s.graphics.drawCircle(0, 0, 10);
s.x = x;
s.y = y;
return s;
}
}
}
import flash.display.Sprite;
import flash.text.TextField;
import org.osmf.net.httpstreaming.f4f.Box;
class Box extends Sprite
{
public function Box(id:int)
{
node = new Node(null, null, new Data(0, id, this));
this.id = id;
graphics.beginFill(Math.random() * 0xffffff);
graphics.drawRect(0, 0, 50, 50);
var tf:TextField = new TextField();
addChild(tf);
tf.text = id.toString();
}
public var id:int;
public var node:Node;
}
class Node
{
public function Node(pre:Node, next:Node, data:Data)
{
this.pre = pre;
this.next = next;
this.data = data;
}
public var data:Data;
public var next:Node;
public var pre:Node;
}
class Data
{
public function Data(x:int, id:int, box:Box)
{
this.x = x;
this.id = id;
this.box = box;
}
public var box:Box;
public var id:int;
public var x:int;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment