การทำ zoom in,zoom out, drag ในเฟลช(flash8)
posted on 28 Jan 2008 16:06 by inmyhead in saraวันนี้แอบทำงานคนอื่่น ในเวลางาน
คือได้โจทย์มาว่า "ทำแบบนี้ได้มั้ยฝ้าย " --->ตามลิงค์นี้
มันก็ใช้เฟลชทำ โดยใช้เมาส์ซูมเข้าออกได้ แล้วก็ลากดูรูปไปมาได้
ดูตอนแรกก็ไม่น่าจะยาก เพราะเคยทำแนวนี้มาก่อน แต่ค่อนข้างนะนานแล้ว
สมองทำการ auto delete ความทรงจำ เหอๆ --" ต้องใช้เวลารื้อฟื้นกันก่อน
ทำเสร็จก็เขียนบล็อคเอาไว้อ่านทีหลังได้
วิธีการทำ
- ต้องมีโปรแกรมเฟลช อ่ะ ชัวร์อยู่แล้ว และต้องมีความรู้ทาง action script
- เริ่มด้วยการใส่รูปภาพเข้าไป ใช้รูปใหญ่ๆ ที่ชัดเจน
- ทำรูปภาพนั้นเป็น mc(movie clip) ตั้งชื่อ mc เป็น mymc(ตั้งให้แนวกว่านี้ไม่ได้เรอะ) แล้วใส่โค๊ดบน mc ดังนี้
on(press) {
startDrag(this);
_root.answer1="";
}
on(release) {
stopDrag();
if (this._droptarget == "/bow") {
_root.answer1="Correct";
}
else{
_root.answer1 = "wrong";
}
}
- แล้วก็สร้างปุ่มขึ้นมาชื่อว่า zoombot,zoomin,startbot
- เพิ่มเฟรม action ขึ้นมา ใส่โค๊ดดังนี้
/////////////////////set begin
with(mymc){
_xscale =30;
_yscale =30;
_x=110.6;
_y=-3;
}
//////////////////// for zoom scroll mouse
mouseWheelListener = new Object();
mouseWheelListener.onMouseWheel = function(delta) {
if(delta > 0){
mymc._xscale*=0.9;
mymc._yscale*=0.9;
}else{
mymc._xscale*=1.1;
mymc._yscale*=1.1;
}
}
Mouse.addListener(mouseWheelListener);
/////////////// on back to start botton click
startbot.onRelease = function() :Void{
with (mymc){
_xscale =30;
_yscale =30;
_x=110.6;
_y=-3;
}
}
/////////////// on zoom out botton click
zoombot.onRelease = function():Void{
with (mymc){
_xscale -=10;
_yscale -=10;
}
}
/////////////// on zoom in botton click
zoomin.onRelease = function():Void{
with (mymc){
_xscale +=10;
_yscale +=10;
}
}
- แค่นี้ก็เสร็จละ แต่กว่าจะเสร็จต้องเปิดเว็บกันหลายตลบ
อีกอันสมบูรณ์กว่า แต่ก็ซูมแปลกๆ
้
ขอขอบคุณความรู้จากไซเบอร์
http://www.thescripts.com/forum/thread741914.html
http://www.flashadvisor.com
http://www.actionscript.org/
ปล. อินเตอร์เน็ตมีประโยชน์หากรู้จักใช้
edit @ 28 Jan 2008 17:00:31 by inmyhead
#1 By papermarche on 2008-01-30 09:28