第二話 ActionScript 應用I
EX1.MoiveClip屬性控制

在老鼠影片片段元件上的實體名稱:mouse

在隱藏按鈕元件上的ActionScript:

on (release) {
_root.mouse._visible=0;
}

on (release) {
_root.mouse._visible=1;
}

在透明按鈕元件上的ActionScript:
on (release) {
_root.mouse._alpha+=10; //透明度遞增10%
}

on (release) {
_root.mouse._alpha-=10; //透明度遞減10%
}

在旋轉按鈕元件上的ActionScript:
on (release) {
_root.mouse._rotation+=10; //旋轉角度遞增10%
}

on (release) {
_root.mouse._rotation-=10; //旋轉角度遞減10%
}


 
EX2.電子時鐘

上方動態文字的變數為nowdate,下方動態文字的變數為nowtime

在文字時間影片片段元件上的ActionScript:

onClipEvent(load){
time=new Date();
}
onClipEvent(enterFrame){
hours=time.getHours();
minutes=time.getMinutes();
seconds=time.getSeconds();
todaydate=time.getDate();
month=(time.getMonth()+1);
year=time.getFullYear();

if(length(hours)==1){
hours="0"+hours;
}
if(length(minutes)==1){
minutes="0"+minutes;
}
if(length(seconds)==1){
seconds="0"+seconds;
}
if(length(todaydate)==1){
todaydate="0"+todaydate;
}
if(length(month)==1){
month="0"+month;
}
nowtime=hours+":"+minutes+":"+seconds;
nowdate=month+"/"+todaydate+"/"+year;
delete time;
time=new Date();
}


在指針時間影片片段元件上的ActionScript:

onClipEvent(load){
time=new Date();
}
onClipEvent(enterFrame){
hours=time.getHours();
minutes=time.getMinutes();
seconds=time.getSeconds();
todaydate=time.getDate();
month=(time.getMonth()+1);
year=time.getFullYear();

hours=hours*30+int(minutes/2);
minutes=minutes*6+int(seconds/10);
seconds=seconds*6;

delete time;
time=new Date();
}

在時針影片片段元件上的ActionScript:

onClipEvent (enterFrame) {
setProperty(this, _rotation, _parent.hours);
}

在分針時間影片片段元件上的ActionScript:

onClipEvent (enterFrame) {
setProperty(this, _rotation, _parent.minutes);
}

在秒針時間影片片段元件上的ActionScript:

onClipEvent (enterFrame) {
setProperty(this, _rotation, _parent.seconds);
}