
选择第一帧添加如下代码。
| //Height of each blade of grass grassheight=35; //Average space in between each blade of grass grassspacing=5; //Maximum sway of each blade of grass maxsway=20; //Number of blades of grass along the x axis xplots=30; //Number of blades of grass along the y axis yplots=20; //The wind has an x position and the grass is attracted to the position windxpos=0; //Velocity of the wind left and right windspeed=0; //Gives the grass a bent effect. The grass bends 1/4 of the way up grasscontrol=grassheight/4; //Array containing the info for each blade of grass grasscoords=[]; //These loops go through the field, planting each blade of grass for (xpos=0; xpos<xplots; xpos++) { for (ypos=0; ypos<yplots; ypos++) { //x position, y position, sway, and color grasscoords.push([xpos*grassspacing+Math.random()*grassspacing,ypos*grassspacing+Math.random()*grassspacing,0,Math.round(Math.random()*128)*65536+Math.round(Math.random()*76+146)*256]); } } //Run on each frame onEnterFrame=function(){ //Clear all of the grass so it can be redrawn with different sway this.clear(); //Change the speed of the wind windspeed=Math.max(-50,Math.min(50,windspeed+Math.random()*40-20)); //Move the position the blades are attracted according to the windxpos windxpos+=windspeed; //If the windxpos moves too far to the left, reverse its speed if(windxpos<-100){ windxpos=-100; windspeed*=-1; } //If the windxpos moves too far to the right, reverse its speed else if(windxpos>grassspacing*xplots+100){ windxpos=grassspacing*xplots+100; windspeed*=-1; } //handle the redraw for each blade of grass for(coord=0;coord<grasscoords.length;coord++){ //Set the line style. 0 means use hairline width and grasscoords[coord][3] is the color this.lineStyle(0, grasscoords[coord][3], 100, false, "normal", "none", "none", 1); //Adjust the sway according to the grass's current sway and the windxpos grasscoords[coord][2]=Math.max(-maxsway,Math.min(maxsway,grasscoords[coord][2]+Math.max(-maxsway,Math.min(maxsway,(windxpos-grasscoords[coord][0])/100))))+(Math.random()*3-1.5); //Move to the base of the blade of grass this.moveTo(grasscoords[coord][0],grasscoords[coord][1]); //Draw a curved line to the new top of the blade of grass this.curveTo(grasscoords[coord][0],grasscoords[coord][1]-grasscontrol,grasscoords[coord][0]+grasscoords[coord][2],grasscoords[coord][1]-grassheight+Math.abs(grasscoords[coord][2]/2)); } } |
然后回到主场景中,建立两个图层,下面的为云的图层,上面的为草的图层,这里我绘制了一个放草的框框。

按Ctrl+L打开库分别把草元件和云元件放到相应的图层。给草命名实例grass。

最后可以测试影片了!但是好象机器运行速度在减慢啊!祝你好运!