最近工做中用到個Flash效果,很久沒有寫FlashAS腳本了,就想從之前寫的代碼中找一些實例。居然看到硬盤中還留有若干年前的代碼。數組
這個時鐘效果是所有采用腳本實現,圖形也是用腳本繪製的。寫於2005年,固然仍是基於As2.0編寫。如今想一想本身當時也是閒得沒事兒,居然寫這個東東。呵呵。2005年啊,8年前……無限回味啊,當初本身仍是個小菜鳥,寫出這樣的東西真不容易,如今都想不起怎麼寫出來的了。裏面用到了圓方程!當時剛出校門,理論基礎還算紮實,如今什麼都忘記了。dom
如今也能夠用,使用很簡單,把代碼複製到幀的動做面板中便可。代碼以下:函數
/* 一個表的效果,全AS繪製,只需把一下面的代碼全複製到 第一幀就OK了。 做者:晴風 10522779
*/ //生成元件的起始深度值 var lv:Number = 100; //鐘錶的半徑 var radius:Number = 100; // 鐘錶跟隨鼠標的速度 var speed:Number = 5; //鐘錶的顏色值及透明度 var my_color = 0xB1C0F3; var my_line = 0xffffff; var my_alpha = 100; //用於圓形方程計算 var p:Number = 0; var n:Number = 0; //設定文本樣式的函數 function text_CSS(word) { CSS = new TextFormat(); CSS.size = radius*.14; //文本居中 CSS.align = "center"; //文本的顏色 CSS.color = my_color; //CSS.color = Math.floor(Math.random()*255) << 16 | Math.floor(Math.random()*255) << 8 | Math.floor(Math.random()*255); word.setTextFormat(CSS); } //生成一續列,動態文本字段 for (i=0; i<=30; i++) { createTextField("time"+i, lv++, 0, 0, radius*0.2, radius*.2); this["time"+i].selectable = false; this["time"+i]._alpha = my_alpha/3; } //生成標誌文本 createTextField("biaozi", lv++, 0, 0, radius*0.6, radius*0.2); biaozi.text = "晴風時鐘"; biaozi._alpha = my_alpha/3; text_CSS(biaozi); //繪製中心點 createEmptyMovieClip("zhongxin", lv++); with (zhongxin) { beginFill(0xffffff, my_alpha); moveTo(-2, 2); lineTo(2, 2); lineTo(2, -2); lineTo(-2, -2); lineTo(-2, 2); endFill(); _x = 200; _y = 150; _width = _height=radius*.04; } //繪製時針 createEmptyMovieClip("shi", lv++); with (shi) { beginFill(my_color, my_alpha); lineStyle(1, my_line, my_alpha/2); moveTo(-5, 6); lineTo(0, 10); lineTo(5, 6); lineTo(3, -35); lineTo(0, -37); lineTo(-3, -35); lineTo(-5, 6); endFill(); _x = _parent.zhongxin._x; _y = _parent.zhongxin._y; _height = radius*.50; _width = _height*.25; } //繪製分針 createEmptyMovieClip("fen", lv++); with (fen) { beginFill(my_color, my_alpha/3*2); lineStyle(1, my_line, my_alpha); moveTo(-3, 10); lineTo(0, 13); lineTo(3, 10); lineTo(2, -60); lineTo(-2, -60); lineTo(-3, 10); endFill(); _x = _parent.zhongxin._x; _y = _parent.zhongxin._y; _height = radius*.65; _width = _height*.15; } //繪製秒針 createEmptyMovieClip("miao", lv++); with (miao) { beginFill(my_color, my_alpha/2); moveTo(-1.5, 15); lineTo(1.5, 15); lineTo(.5, -65); lineTo(-.5, -65); lineTo(-1.5, 15); endFill(); //繪製秒針上的紅星 beginFill(my_color, my_alpha); moveTo(-2, -53); lineTo(2, -53); lineTo(2, -55); lineTo(-2, -55); lineTo(-2, -53); endFill(); _x = _parent.zhongxin._x; _y = _parent.zhongxin._y; _height = radius*.7; _width = _height*.05; } //繪製刻度 for (m=1; m<=12; m++) { createEmptyMovieClip("kedu"+m, lv++); with (this["kedu"+m]) { //刻度爲幾邊形的圖案 var num:Number = 6; //刻度的半徑 var r:Number = radius*0.12; var p:Number = 2*Math.PI/num; var start_x:Array = new Array(); var start_y:Array = new Array(); for (i=0; i<num; i++) { start_x[i] = Math.sin(p*i)*r; start_y[i] = Math.cos(p*i)*r; lineStyle(.5, my_color, my_alpha/1.5); for (n=0; n<num; n++) { moveTo(start_x[i], start_y[i]); lineTo(start_x[n], start_y[n]); } } } } //中心點調到最前面 zhongxin.swapDepths(lv+1000); onEnterFrame = function () { now_date = new Date(); zhongxin._rotation = now_date.getSeconds()*12; miao._rotation = now_date.getSeconds()*6; fen._rotation = now_date.getMinutes()*6; // +now_date.getSeconds()*.1; shi._rotation = now_date.getHours()*30+now_date.getMinutes()*.5; // 當前時間數組,依次爲:年,月,日,周,時,分,秒。 var now = new Array(now_date.getFullYear(), now_date.getMonth()+1, now_date.getDate(), now_date.getDay(), now_date.getHours(), now_date.getMinutes(), now_date.getSeconds()); var xingqi = new Array("日", "一", "二", "三", "四", "五", "六"); var riqi = now[0]+"年"+now[1]+"月"+now[2]+"日"+" "+"星期"+xingqi[now[3]]; var shijian = now[4]+"點"+now[5]+"分"+now[6]+"秒 "; var now_time:String; switch (Math.floor(now[4]/4)) { case 0 : now_time = riqi+" "+"凌晨"+" "+shijian; break; case 1 : now_time = riqi+" "+"早上"+" "+shijian; break; case 2 : now_time = riqi+" "+"上午"+" "+shijian; break; case 3 : now_time = riqi+" "+"中午"+" "+shijian; break; case 4 : now_time = riqi+" "+"下午"+" "+shijian; break; case 5 : now_time = riqi+" "+"晚上"+" "+shijian; break; } p = 2*Math.PI/now_time.length; for (i=0; i<=now_time.length; i++) { // 逐個給動態文本賦值 this["time"+i].text = now_time.charAt(i); // 引用函數text_CSS,設定動態文本樣式 text_CSS(this["time"+i]); var mc = this["time"+i]; mc._y += ((Math.cos(n+p*i)*radius+zhongxin._y-radius*0.1)-mc._y)/speed; mc._x += ((Math.sin(n+p*i)*radius+zhongxin._x-radius*0.1)-mc._x)/speed; // mc._yscale = mc._xscale=(mc._y-bb._y)/2+100; mc.swapDepths(lv+mc._y-zhongxin._y); } // 轉動速度 n -= .02; // 時針.分針.秒針,所有跟隨中心點,中心點隨鼠標 shi._x = fen._x=miao._x=zhongxin._x += (_xmouse+radius*1.2-zhongxin._x)/speed; shi._y = fen._y=miao._y=zhongxin._y += (_ymouse+radius*1.2-zhongxin._y)/speed; // 標誌也跟隨中心點 biaozi._x += (zhongxin._x-biaozi._x)/speed-biaozi._width/10; biaozi._y += (zhongxin._y+radius*0.3-biaozi._y)/speed; // 佈置刻度 p = 2*Math.PI/12; for (i=1; i<=12; i++) { this["kedu"+i]._y += ((Math.cos(p*i)*radius*.75+zhongxin._y)-this["kedu"+i]._y)/speed; this["kedu"+i]._x += ((Math.sin(p*i)*radius*.75+zhongxin._x)-this["kedu"+i]._x)/speed; } updateAfterEvent(); };
源文件下載:watch.rarthis