วันจันทร์ที่ 22 กรกฎาคม พ.ศ. 2556

action script 3.0 กับ helloworld

1.สร้าง movieclip ชื่อว่า btn1 กด f8 แปลงเป็น button ซะ
2.สร้าง layer บน timeline ใหม่่ ตั้งชื่อว่า as แล้วเขียน code ใน frame
(เพื่อแยก layer ระหว่าง code กับ กราฟฟิก) 

//code btn1.addEventListener(MouseEvent.CLICK,atk);//ปุ่ม btn1 เื่เมื่อclick แล้วจะเรียกใช้ฟังชั้น atk 


function atk(MouseEvent)//ฟังชั่น atk
{

 var hello:String = "hello world"; //ประกาศตัวแปร แล้วใส่ text ว่า helloworld
 result1.text=""+hello+""; //
output trace(hello);//trace ดูต่าตัวแปรว่าถูกต้องไหม บรรทัดนี้ไม่ใส่ก็ได้ครับ

 }

ตัวอย่างที่2 ควบคุม mc ให้เล่นโดยใช้ gotoAndPlay
stop();
mc1.stop();
mc1.addEventListener(MouseEvent.CLICK,atk);

function atk(MouseEvent)
{
mc1.gotoAndPlay(2);
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น