国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 辦公 > Flash > 正文

Flash制作旋轉小星星動畫實例教程(代碼實現)

2020-07-17 13:12:38
字體:
來源:轉載
供稿:網友

具體制作過程如下:

1、新建一個fla文件,寬400高400,幀頻默認,背景顏色黑色,保存。

2、選擇多邊形工具,設置為5邊,星形。在舞臺上畫一個任意顏色、大小的星。

3、在選取狀態下,右鍵轉換為影片剪輯,全對齊,命名為Star,刪除舞臺上的星。

4、按Ctrl+L組合鍵,打開庫面板,右鍵單擊Star影片剪輯,選擇“屬性”打開元件屬性面板,勾選ActionScript選項,這樣就使影片剪輯與Star類進行了綁定。如圖:

/

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、好了,所有的工作都已經完成,測試你的影片。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上栗县| 伊宁市| 剑川县| 安宁市| 开鲁县| 无锡市| 康保县| 新宁县| 牡丹江市| 雅江县| 黄大仙区| 保康县| 聂荣县| 中宁县| 米脂县| 江孜县| 平和县| 广灵县| 陕西省| 阳信县| 新河县| 大渡口区| 赣榆县| 塔城市| 迭部县| 仙游县| 潞西市| 宝鸡市| 庆城县| 乐东| 福鼎市| 商水县| 荆门市| 南和县| 花莲市| 崇左市| 石楼县| 建始县| 亚东县| 揭西县| 弥渡县|