首页产品库评测行情新闻|手机数码笔记本台式机DIY硬件数字家庭数码相机办公外设|软件下载游戏开发|社区

更多

数码相机
MP4
LCD
机箱
音箱

软件资讯设计 工具 系统 开发 安全 办公 陶吧 IT教育 Windows 7 | 下载中心天极下载中心诚征下载通路合作伙伴
天极网 > 软件频道 > 设计在线 > flash>Flash AS3代码制作旋转彩色五星动画

Flash AS3代码制作旋转彩色五星动画

2010-02-01 08:20作者:论坛整理出处:天极网软件频道责任编辑:杨玲

  本文介绍用Flash和AS代码制作漂亮的旋转五星动画的方法和步骤,主要用到库元件与外部类进行类绑定的操作。Star类定义了两个方法:星的颜色和旋转。fla的代码是一个for循环,调用Star类的构造函数,生成100个星的实例,随机摆放,并显示在舞台上。


flash动画效果展示

  制作步骤如下。

  1、新建一个fla文件,宽400高400,帧频默认,背景颜色黑色,保存。

  2、选择多边形工具,设置为5边,星形。在舞台上画一个任意颜色、大小的星。

  3、在选取状态下,右键转换为影片剪辑,全对齐,命名为Star,删除舞台上的星。

  4、按Ctrl+L组合键,打开库面板,右键单击Star影片剪辑,选择“属性”打开元件属性面板,勾选ActionScript选项,这样就使影片剪辑与Star类进行了绑定。如图:

Flash AS3代码制作旋转彩色五星动画
图示:勾选ActionScript选项

  5、下面开始编写Star类的代码,新建一个ActionScript文件。

  输入下面的代码:

以下是代码片段:

package {
        import flash.display.MovieClip;
        import flash.geom.ColorTransform;
        import flash.events.*;
        public class Star extends MovieClip {
                private var starColor:uint;
                private var starRotation:Number;
                public function Star () {
                        //Calculate a random color
                        this.starColor = Math.random() * 0xffffff;
                        // Get access to the ColorTransform instance associated with star.
                        var colorInfo:ColorTransform = this.transform.colorTransform;
                        // Set the color of the ColorTransform object.
                        colorInfo.color = this.starColor;
                        // apply the color to the star
                        this.transform.colorTransform = colorInfo;
                        //Assign a random alpha for the star
                        this.alpha = Math.random();
                        //Assign a random rotation speed
                        this.starRotation =  Math.random() * 10 - 5;
                        //Assign a random scale
                        this.scaleX = Math.random();
                        this.scaleY = this.scaleX;
                        //Add ENTER_FRAME where we do the animation
                        addEventListener(Event.ENTER_FRAME, rotateStar);
                }
                //This function is responsible for the rotation of the star
                private function rotateStar(e:Event):void {
                        this.rotation += this.starRotation;
                }
        } }

  6、保存在fla同一目录下,保存名为Star.as。注意:这一步非常重要,一定要同fla主文件保存在相同的目录下,如果保存在其它的目录下,要指明路径。初学者在测试时往往出现找不到类的错误提示,问题都在这里。

  7、返回到fla,在第1层的第一帧输入代码:
 

以下是代码片段:

for (var i = 0; i < 100; i++) {
        var star:Star = new Star();
        star.x = stage.stageWidth * Math.random();
        star.y = stage.stageHeight * Math.random();
        addChild (star);
 }

  点击下载源文件

 

共1页。 1
进入 最权威的Windows 7论坛 查看网友讨论

软件频道最新更新

热点推荐

IT嘉年华

Flash MX动画制作实例教程


立即下载
  • 文件大小:0
  • 下载次数:188909
  • 更新日期:2004-07-08
  • 软件版本:
  • 适用平台:WIN98/ME/2000/NT/XP/2003
  • 软件类型:0

编辑推荐

软件下载

热门
推荐

网友关注

软件
资料
游戏

装机推荐

文章排行

本周
本月
最新更新
天极服务|关于我们|About us|网站律师|RSS订阅|友情合作|加入我们|天极动态|网站地图|意见反馈|MSN/QQ上看天极
Copyright (C) 1999-2012 Yesky.com, All Rights Reserved 版权所有 天极网络