<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)" >
<fx:Script>
<![CDATA[
import caurina.transitions.Tweener;
import mx.events.FlexEvent;
private var initX:int=500;
private var initY:int=200;
private var gap:int=30;
private var _scale:Number=.6;
private var _current:int;
private var time:Number=0.5;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
setCurrent(3,false);
}
private function currentInd(offset:int,len:uint):int
{
var temp:int=_current+offset;
if(temp>=len)
return temp%len;
else if(temp<0)
return len+temp;
else return temp;
}
private function setCurrent(ind:int,move:Boolean=true):void
{
var len:uint=menu_group.numElements;
_current=ind;
if(_current>=len)_current=0;
else if(_current<0)_current=len-1;
var _canvas:Canvas;
for(var i:int=-2;i<=2;i++)
{
var v:int=(Math.abs(i)==2)?0:1;
var t:Number=(Math.abs(i)==2)?.1:time;
var c:Number=Math.pow(_scale,Math.abs(i));
var x:Number;
var y:Number;
_canvas=menu_group.getChildAt(currentInd(i,len)) as Canvas;
y=(i==0)?initY:initY+(_canvas.height/2)-(_canvas.height*_scale/(2*Math.abs(i)));
switch(i)
{
case 0:x=initX;break;
case 1:x=initX+_canvas.width+gap;break;
case 2:x=initX+_canvas.width+gap*1.5;break;
case -1:x=initX-(_canvas.width*_scale)-gap;break;
case -2:x=initX-(_canvas.width*_scale)-gap*.5;break;
}
if(move)
Tweener.addTween(_canvas, {visible:v,scaleX:c,scaleY:c,x:x,y:y,time:t});
else
{
_canvas.x=x;
_canvas.y=y;
_canvas.scaleX=_canvas.scaleY=c;
_canvas.visible=Boolean(v);
}
}
}
protected function button1_clickHandler(event:MouseEvent):void
{
setCurrent(_current+1);
}
protected function button2_clickHandler(event:MouseEvent):void
{
setCurrent(_current-1);
}
protected function type_1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
}
]]>
</fx:Script>
<s:Group id="menu_group">
<mx:Canvas visible="false" backgroundColor="0xff0000" width="100" height="100" click="type_1_clickHandler(event)"/>
<mx:Canvas visible="false" backgroundColor="0x00ff00" width="100" height="100" click="type_1_clickHandler(event)"/>
<mx:Canvas visible="false" backgroundColor="0x0000ff" width="100" height="100" click="type_1_clickHandler(event)"/>
<mx:Canvas visible="false" backgroundColor="0xffff00" width="100" height="100" click="type_1_clickHandler(event)"/>
<mx:Canvas visible="false" backgroundColor="0x00ffff" width="100" height="100" click="type_1_clickHandler(event)"/>
<mx:Canvas visible="false" backgroundColor="0xff00ff" width="100" height="100" click="type_1_clickHandler(event)"/>
<mx:Canvas visible="false" backgroundColor="0x123456" width="100" height="100" click="type_1_clickHandler(event)"/>
<mx:Canvas visible="false" backgroundColor="0x654321" width="100" height="100" click="type_1_clickHandler(event)"/>
</s:Group>
<mx:HBox>
<s:Button click="button2_clickHandler(event)"/>
<s:Button click="button1_clickHandler(event)"/>
</mx:HBox>
</s:Application>
2011年9月20日 星期二
as3 [flex]旋轉選單
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言