สวัสดีครับวันนี้พอดีอยากลอง script ใน CS4 ที่ทำงานกับแกน Z เลยได้แบบนี้ออกมา อ้อ เครื่องต้องลง Flash Player 10 นะครับ Flash Player 9 เปิดแล้วใบไม้จะไม่พลิ้ว..
http://www.codeartschool.com/test/myLeafFall.swfมาดูวิธีทำ1. สร้าง MC ขึ้นมาตัวนึงรูปอะไรก็ได้ ในที่นี่ผมวาดเป็นรูปใบไม้
2.ไปคลิ๊กขวาเลือก Property เลือกตั้งชื่อ Class เป็น "mcLeaf"
3.ก๊อปปี้ script ด้านล่างนี้ไปแปะที่เฟรม
4. กด Ctrl+Enter ทดสอบ
var num:int=50;
var spdX:int=2;
var spdY:int=5;
for(var i:int=1;i<=num;i++){
var myLeaf:mcLeaf=new mcLeaf();
myLeaf.x=Math.random()*550;
myLeaf.y=Math.random()*400;
myLeaf.rotationX=(Math.random()*360)-180;
myLeaf.rotationY=(Math.random()*360)-180;
myLeaf.rotationZ=(Math.random()*360)-180;
myLeaf.scaleY=myLeaf.scaleX=myLeaf.alpha=(Math.random()*0.5)+0.5;
myLeaf.name="l"+i;
myLeaf.degree=Math.floor(Math.random()*360);
myLeaf.dir=Math.floor(Math.random()*2);
addChild(myLeaf);
}
stage.addEventListener(Event.ENTER_FRAME,fall);
function fall(event:Event){
for(i=1;i<=num;i++){
var mc:MovieClip=MovieClip(this.getChildByName("l"+i));
var radian:Number=(mc.degree*Math.PI)/180;
if(mc.dir==0){
mc.x+=Math.cos(radian)*spdX*mc.scaleX;
}else{
mc.x-=Math.cos(radian)*spdX*mc.scaleX;
}
mc.degree+=5;
mc.y+=spdY*mc.scaleX;
mc.rotationX+=(Math.random()*10)-5;
mc.rotationY+=(Math.random()*10)-5;
mc.rotationZ+=(Math.random()*10)-5;
mc.scaleZ=mc.scaleY=mc.scaleX+=(Math.random()*0.2)-0.1;
if(mc.y>stage.stageHeight){
mc.y=-10;
mc.x=Math.random()*stage.stageWidth;
mc.scaleZ=mc.scaleY=mc.scaleX=1
}else if((mc.y<0)&&(mc.scaleX<0)){
mc.scaleY=mc.scaleX=mc.alpha=(Math.random()*0.5)+0.5;
}
}
}