Flash Tuts: ทำให้วัตถุวิ่งตามตำแหน่งที่ mouse คลิก
Posted by kkool | Filed under Flash Actionscript & Design
Please enable Javascript and Flash to view this Flash video.Flash Tuts นี้ก็เป็นการอธิบายวิธีการทำให้วัตถุลอยตามไปยังตำแหน่งที่ mouse คลิก
น่าจะมีประโยชน์นะครับ ลองเข้าไปอ่านรายละเอียดดู ไม่น่าจะยากเกินไป

Step1. สร้างแฟลชใหม่ขึ้นมาซักตัวนึง ในที่นี้ผมใช้ 400×250 px
Step2. สร้าง object ขึ้นมาตัวนึง อันนี้แหละที่จะลอยไปตามที่ mouse click ตั้งชื่อ instance name ว่า “dot”
Step3. สร้าง layer ใหม่ขึ้นมาตั้งชื่อว่า action แล้วก็เอา script นี้ไปแปะไว้
movedot = function () {
this.dx = (this.targx-this._x)*.1;
this.dy = (this.targy-this._y)*.1;
this._x += this.dx;
this._y += this.dy;
};
setTarget = function () {
this.targx = _root._xmouse;
this.targy = _root._ymouse;
};
dot.targx = 10;
dot.targy = 10;
dot.onEnterFrame = movedot;
dot.onMouseDown = setTarget;
เรียบร้อย ลอง Ctrl+Enter เช็คดูว่าลากได้มั๊ย
ลองเอาไปปรับใช้กันดูนะครับ
Download the FLA for this tutorial
Tags: Flash Actionscript & Design




