Flash在3D应用领域非常广阔,使用Flash可以很轻松的做出一些精彩奇妙的3D特效,而且许多效果可以响应鼠标的动作,此实例就是一个鼠标3D感应的效果,通过移动鼠标,可以影响影片中的3D小球,最终效果如图1所示:
图1 最终效果
1.启动Flash,新建一个影片,设置影片的舞台大小为250px*250px(单位为象素),设置影片的背景颜色为黑色.
2.新建一个影片剪辑元件,命名为Ball,进入元件的编辑区后,使用椭圆工具绘制一个正圆,然后打开混色器面板,在面板中设置填充类型为放射渐变,分别设置色带下左右两个色块的颜色,如图2所示:
图2 设置填充色
其中左边色块的RGB颜色代码为(103,152,116),右边色块的RGB颜色代码为(0,0,0),小球填充后的效果如图3所示:
图3 填充颜色后的小球
3.新建一个影片剪辑元件,命名为Point,进入元件的编辑区后,从库中将元件Ball拖到编辑区中,然后在属性面板中给其设置实例名为bLur,如图4所示;
图4 给小球设置实例名
4.还是新建一个影片剪辑元件,命名为Balls,进入元件的编辑区后,将影片默认的图层重命名为Point,然后将元件Point拖到编辑区中,同时在属性面板中设置其实例名为Point,如图5所示;
图5 设置实例名Point
在上面新建一个图层Actions,用来设置控制影片的Action动作脚本.
给第1帧添加如下Action:
x1 = "0" y1 = "0"; z1 = "50"; x2 = "0"; y2 = "0"; z2 = "-50"; x3 = ".1"; y3 = ".1"; z3 = ".1"; x4 = "0"; y4 = "0"; z4 = "-100"; x5 = "-50"; y5 = "-50"; z5 = "50"; x6 = "50"; y6 = "-50"; z6 = "50"; x7 = "50"; y7 = "50"; z7 = "50"; x8 = "-50"; y8 = "50"; z8 = "50"; d = "900"; z0 = "1000"; i = "1"; while (Number(i)<9) { duplicateMovieClip("point", "point" add i, 20-(i*2)); set("zsort" add i, i); i = Number(i)+1; }
给第2帧添加如下Action:
yangle = int(/:yangle); xangle = int(/:xangle); i = "1"; while (Number(i)<9) { cosYangle = eval ( "/:cos" add yangle ); sinYangle = eval ( "/:sin" add yangle ); cosXangle = eval ( "/:cos" add xangle ); sinXangle = eval ( "/:sin" add xangle ); zpos = eval("z" add i); xpos = eval("x" add i); ypos = eval("y" add i); tempz = ((eval("z" add i) ) * cosYangle ) - ( eval ("x" add i) * sinYangle ); set("x" add i, Number((zpos*sinYangle))+Number((xpos*cosYangle))); set("z" add i, Number(((ypos)*sinXangle))+Number((tempz*cosXangle))); set("y" add i, ((ypos)*cosXangle)-(tempz*sinXangle)); scalar = 1/ ( ((eval ("z" add i))/d)+1 ); set("xp" add i, ((eval("x" add i) * scalar) + 00)); set("yp" add i, ((eval("y" add i) * scalar) + 00)); set("unseen" add i, true); i = Number(i)+1; } n = "2"; while ((Number(n)<9)) { i = 8; dummy = "nada"; while (Number(i)>=Number(n)) { if (eval ("z" add eval("zsort" add (i-1))) > eval ("z" add eval("zsort" add i))) { dummy = eval("zsort" add (i-1)); set("zsort" add (i-1), eval("zsort" add i)); set("zsort" add i, dummy); } i = i-1; } if (dummy eq "nada") { n = 9; } n = Number(n)+1; } i = "1"; while (Number(i)<9) { /:blur = int (15 - (eval( "z" add eval ("zsort" add i) )/5)); tellTarget ("point" add i add "/blur") { gotoAndStop(/:blur); } setProperty("point" add i, _xscale, 100 - ((eval( "z" add eval ("zsort" add i))) /5)); setProperty("point" add i, _yscale, 100 - ((eval( "z" add eval ("zsort" add i))) /5)); setProperty("point" add i, _x, eval( "xp" add eval ("zsort" add i) )); setProperty("point" add i, _y, eval( "yp" add eval ("zsort" add i) )); i = Number(i)+1; }
给第3帧添加如下Action:
gotoAndPlay(2);
最后时间轴如图6所示:
图6 元件Balls的时间轴窗口
|