|
Flash5 畫任意直線教程
第一步:新建一個flash,並且建立一個mc(命名為line),並在library裡輸出為line mc裡面是長度為100的水平直線(一定是極細線),中心坐標是(50,0)
第二步:建立連線基礎類,並且建立幾個設置的成員函數,具體程序如下,請放在要畫線的場景或mc的第一幀裡,並單獨放在一個名為class的層裡,action如下:
function New_line(c_line) { this.c_line=c_line; } New_line.prototype.attach_line=function(c_deep) { this.deep=c_deep+0; attachMovie(this.c_line,this.c_line+this.deep,this.deep); return ++c_deep; }; New_line.prototype.set_xy=function(c_x,c_y) { eval(this.c_line+this.deep)._x=c_x; eval(this.c_line+this.deep)._y=c_y; }; New_line.prototype.set_width=function(c_dx,c_dy) { this.dx=c_dx; this.dy=c_dy; this.l=Math.sqrt(this.dx*this.dx+this.dy*this.dy); eval(this.c_line+this.deep)._width=this.l; }; New_line.prototype.set_angle=function() { this.angle=180*Math.atan(this.dx/this.dy)/Math.PI; if(this.dy>=0) this.angle+=180; eval(this.c_line+this.deep)._rotation=90-this.angle; }; New_line.prototype.set_color=function(c_color) { this.mycolor=new Color(this.c_line+this.deep); this.mycolor.setRGB(c_color); }; New_line.prototype.delete_line=function(c_object) { removeMovieClip(this.c_line+this.deep); delete eval(c_object); }
第三步:建立實現連線函數,放在class層的下層,命名為function的層裡,具體action如下:
function line(c_x1,c_y1,c_x2,c_y2,c_color){ this.myline=new New_line("line"); deep=this.myline.attach_line(deep); this.myline.set_xy(c_x1,c_y1); this.myline.set_width(c_x1-c_x2,c_y1-c_y2); this.myline.set_angle(); this.myline.set_color(c_color); } line.prototype.delete_line=function(c_object) { this.myline.delete_line("myline"); delete eval(c_object); }
第四步:連線程序的具體用法。它的用法的具體形式如下:
myline = new line(x1,y1,x2,y2,color);
其中x1,y1為畫線起始點的坐標,x2,y2為畫線中止的坐標,color為所畫線的顏色具體形式為#0000FF等十六進制數,也可以用十進制,但不容易看出顏色值。
刪除這條線: myline.delete_line("myline");
用法舉例:在class與function層的下面建立一action層,並且設置兩個關鍵幀 第一幀的action是:
this["myline"+i]=new line(i,-50*Math.sin(i/20),i+4,-50*Math.sin((i+4)/20),0xFF00FF); if(i>=500){ for(i;i>0;i--) this["myline"+i].delete_line("myline"+i); } i +=4; if(ip!=1){ ip=1 myline = new line(0,0,500,0); }
第二幀的action是:
gotoAndPlay(_currentframe -1);
這樣你就能畫出一條標準的正弦曲線了
源文件下載:http://www.blueidea.com/user/goldgoat/line.fla 以上這就是我在工作中總結出來得畫線程序,非常有用,而且用法也非常方便,我曾經用它做過很多優秀得作品,它最大得特點是不必考慮線得深度問題,而且刪除也很方便,相信你一見就會愛不釋手得。
|