2008年3月25日 @ 11:15
AS3 carousel
Flash动画看到了一个不错的运动标志3D效果,可惜是as2的,我把它改成了as3的,有需要的就拿去吧.
点击下载此文件/**
* ...
* @author 杜增强 2008-03-25 10:16
* @link
* @version 0.1
*/
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.*;
public class carousel extends Sprite {
/**
* ball 的数目
*/
private var numOfBalls:Number = 10;
/**
* X轴半径
*/
private var radiusX:Number = 250;
/**
* Y轴半径
*/
private var radiusY:Number = 75;
/**
* X轴中心
*/
private var centerX:Number ;
/**
* Y轴中心
*/
private var centerY:Number;
/**
* 旋转速度
*/
private var speed:Number = 0.05;
public function carousel() {
centerX = this.stage.stageWidth / 2;
centerY = this.stage.stageHeight / 2;
for(var i=0;i<numOfBalls;i++)
{
var t:MovieClip = new ball();
t.name = 'ball' + i;
this.addChild(t);
t.data = i * ((Math.PI * 2) / numOfBalls);
t.addEventListener(Event.ENTER_FRAME, onEnter);
}
this.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
/**
* ENTER_FRAME事件
* @param e
*/
private function onEnter(e:Event):void {
var t:MovieClip = e.target as MovieClip;
//设置坐标
t.x = Math.cos(t.data) * radiusX + centerX;
t.y = Math.sin(t.data) * radiusY + centerY;
//设置scaleX和scaleY
var s = t.y / (centerY + radiusY);
s = (s > 1)?1:s;
t.scaleX = t.scaleY = s;
t.alpha = s;
t.data += speed;
}
/**
* MouseMove事件
* @param e
*/
private function onMouseMove(e:MouseEvent):void {
//速度随鼠标坐标改变而改变
speed = (e.stageX - centerX) / 100;
//radiusX和radiusY随鼠标坐标改变而改变
radiusY = e.stageY - centerY;
radiusX = e.stageX - centerX;
}
}
}
Filed under: 原创 · Tags: as3 carousel
Articles related:
Blur trail effect (2008-3-24 11:29:46)
Graffiti - AS3 Bitmap Drawing Library (2008-3-21 13:53:15)
Fractals in ActionScript 3 -A Flash Tutorial (2008-3-20 11:30:30)
popforge ActionScript 3 code sandbox for various (2008-3-19 18:47:31)
ActionScript 3 RIA Reference Guide (2008-3-18 10:35:20)
PureMVC 2.0.1 Released for the ActionScript 3 (2008-3-11 9:37:10)
Asciify - Actionscript 3 (as3) Ascii Art class (2008-3-6 13:0:28)
ActionScript 3 Class Interface Implementations (2008-3-4 9:17:6)
The AS 3 compiler, asc, is now open-source! (2008-2-22 11:36:48)
[转帖]关于Flex及AS3的百多条小小知识 (2008-2-16 10:38:34)
Leave a Comment
◎welcome to give out your point。

