ActionScript 3 使用Tweener绘制和动画圆圈
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 使用Tweener绘制和动画圆圈相关的知识,希望对你有一定的参考价值。
//First we need to import some classes:
import flash.display.*;
import flash.events.*;
import caurina.transitions.Tweener;
import flash.utils.Timer;
//and declare some varibles:
public var graphic:Sprite;
public var total:Number = 120;
public var track:Sprite;
private var __radius:Number = 25;
private var t:Timer;
private var count:int = 0;
private var targetAlpha:Number = 1;
//In the constructor function we add:
graphic = new Sprite();
addChild( graphic );
track = new Sprite();
track.graphics.lineStyle( 4, 0xFFFFFF, 0.25 );
track.graphics.drawCircle( 0, 0, __radius );
graphic.addChild(track);
for ( var i:int = 0; i < total; i++ )
{
createCircle( i );
}
//And than:
public function loop():void
{
t = new Timer( 1 );
t.addEventListener( TimerEvent.TIMER, onTimer );
t.start();
}
private function onTimer( e:TimerEvent ):void
{
if ( t.currentCount >= total)
{
if ( targetAlpha == 1 )
{
targetAlpha = 0;
}
else
{
targetAlpha = 1;
}
t.stop();
t.reset();
t.start();
}
Tweener.addTween( graphic.getChildByName( "s_" + (t.currentCount - 1) ), { alpha:targetAlpha, time: 1.75, transition:"easeOut" } );
}
private function createCircle( ID:int ):void
{
var singleSliceDegr:Number = 360 / total;
var itemDegr:Number = ID * singleSliceDegr;
var s:Sprite = new Sprite();
s.name = "s_" + ID;
s.graphics.beginFill(0xFFFFFF,1);
s.graphics.drawCircle( 0, 0, 2 );
s.cacheAsBitmap = true;
s.x = __radius * ( Math.cos( ( itemDegr ) * Math.PI / 180 ) );
s.y = __radius * ( Math.sin( ( itemDegr ) * Math.PI / 180 ) );
s.alpha = 0;
graphic.addChild(s);
}
}
以上是关于ActionScript 3 使用Tweener绘制和动画圆圈的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 Tweener例子
ActionScript 3 Tweener - 导入类
[ActionScript 3.0] 幻灯片效果实例
Tweener的Tweening数
Tweener删除tweens
dotween