具體制作過程如下:
1、新建一個fla文件,寬400高400,幀頻默認,背景顏色黑色,保存。
2、選擇多邊形工具,設置為5邊,星形。在舞臺上畫一個任意顏色、大小的星。
3、在選取狀態(tài)下,右鍵轉(zhuǎn)換為影片剪輯,全對齊,命名為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主文件保存在相同的目錄下,如果保存在其它的目錄下,要指明路徑。初學者在測試時往往出現(xiàn)找不到類的錯誤提示,問題都在這里。
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、好了,所有的工作都已經(jīng)完成,測試你的影片。
|
新聞熱點
疑難解答