Flash AS3实例教程:简单的转动的星星-Flash actionscript

紫磐1985

紫磐1985

2016-03-18 15:15

今天天气好晴朗处处好风光,好天气好开始,图老师又来和大家分享啦。下面给大家推荐Flash AS3实例教程:简单的转动的星星-Flash actionscript,希望大家看完后也有个好心情,快快行动吧!

poluoluo核心提示:AS3.0实例:制作转动的星.

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/flash/) 演示:


这是一个非常简单的实例,主要是库元件与外部类进行类绑定的操作。Star类定义了两个方法:星的颜色和旋转。fla的代码是一个for(图老师整理)循环,调用Star类的构造函数,生成100个星的实例,随机摆放,并显示在舞台上。

1、新建一个fla文件,宽400高400,帧频默认,背景颜色黑色,保存。
2、选择多边形工具,设置为5边,星形。在舞台上画一个任意颜色、大小的星。
3、在选取状态下,右键转换为影片剪辑,全对齐,命名为Star,删除舞台上的星。
4、按Ctrl+L组合键,打开库面板,右键单击Star影片剪辑,选择属性打开元件属性面板,勾选ActionScript选项,这样就使影片剪辑与Star类进行了绑定。如图:
sshot-1.png
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);

}8、好了,所有的工作都已经完成,测试你的影片。

附件下载:星.rar
展开更多 50%)
分享

猜你喜欢

Flash AS3实例教程:简单的转动的星星-Flash actionscript

FLASH flash教程
Flash AS3实例教程:简单的转动的星星-Flash actionscript

Flash AS3教程:制作鼠标感应图片转动-Flash实例教程

FLASH flash教程
Flash AS3教程:制作鼠标感应图片转动-Flash实例教程

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Flash AS3教程:ClassLoader类-Flash actionscript

FLASH flash教程
Flash AS3教程:ClassLoader类-Flash actionscript

Flash AS3教程:类的分包处理-Flash actionscript

FLASH flash教程
Flash AS3教程:类的分包处理-Flash actionscript

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

Flash AS3教程:用ActionScript侦测鼠标的位置-Flash actionscript

FLASH flash教程
Flash AS3教程:用ActionScript侦测鼠标的位置-Flash actionscript

Flash AS3简单制作跟随鼠标缓动运动的圆-Flash实例教程

FLASH flash教程
Flash AS3简单制作跟随鼠标缓动运动的圆-Flash实例教程

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Painter基础教程之图像水管

Painter基础教程之图像水管

Corel Painter画猛将张飞

Corel Painter画猛将张飞
下拉加载更多内容 ↓