1. สร้างเอกสารใหม่ขึ้นมาขนาด 180x40 ดังรูป


2. ใช้เครื่องมือ text tool สร้าง textbox ขึ้นมาเลือกเป็น Dynamic Text ตั้งชื่อว่า clock_txt ดังรูป



4. สร้าง layer ใหม่ขึ้นมา ตั้งชื่อว่า action

5. คลิกที่เฟรมแรก กด F9 หรือคลิกขวาแล้วเลือก action

6. ใส่ action script ลงไปดังนี้
time=new Date(); // time object
var seconds = time.getSeconds()
var minutes = time.getMinutes()
var hours = time.getHours()
if (hours<12) {
ampm = "AM";
}
else{
ampm = "PM";
}
while(hours >12){
hours = hours - 12;
}
if(hours<10)
{
hours = "0" + hours;
}
if(minutes<10)
{
minutes = "0" + minutes;
}
if(seconds<10)
{
seconds = "0" + seconds;
}
clock_txt.text = hours + ":" + minutes + ":" + seconds +" "+ ampm;
7. เพิ่มเฟรมขึ้นมาอีกหนึ่งเฟรม ดังรูป

9. ใส่ action script ลงไปในเฟรมที่สอง ดังนี้
gotoAndPlay(1);
10. กด ctrl+enter เพื่อดูผลลัพธ์
ไม่มีความคิดเห็น:
แสดงความคิดเห็น