Flash在3D应用领域非常广阔,使用Flash可以很轻松的做出一些精彩奇妙的3D特效,而且许多效果可以响应鼠标的动作,此实例就是一个鼠标3D感应的效果,通过移动鼠标,可以影响影片中的3D小球,最终效果如下所示:
动画效果:
具体制作步骤:
1.启动Flash,新建一个影片,设置影片的舞台大小为250px*250px(单位为象素),设置影片的背景颜色为黑色.
2.新建一个影片剪辑元件,命名为Ball,进入元件的编辑区后,使用椭圆工具绘制一个正圆,然后打开混色器面板,在面板中设置填充类型为放射渐变,分别设置色带下左右两个色块的颜色,如图1所示:
图1 设置填充色
其中左边色块的RGB颜色代码为(103,152,116),右边色块的RGB颜色代码为(0,0,0),小球填充后的效果如图2所示:
图2 填充颜色后的小球
3.新建一个影片剪辑元件,命名为Point,进入元件的编辑区后,从库中将元件Ball拖到编辑区中,然后在属性面板中给其设置实例名为bLur,如图3所示;
图3 给小球设置实例名
4.还是新建一个影片剪辑元件,命名为Balls,进入元件的编辑区后,将影片默认的图层重命名为Point,然后将元件Point拖到编辑区中,同时在属性面板中设置其实例名为Point,如图4所示;
图4 设置实例名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);
最后时间轴如图5所示:
图5 元件Balls的时间轴窗口
5.因为影片中还需要使用鼠标来对小球进行控制,我们可以利用隐形按钮来实现这一功能.新建一个按钮元件命名为yxbtn,进入元件的编辑区后,只在Hit帧绘制一个图形即可,形状可以随意.然后再新建一个影片剪辑元件,命名为inv,进入元件的编辑区后,将元件yxbtn拖到编辑区中,然后将图层Layer1延伸到第2帧,然后在上面新建一个图层,在第1帧添加如下Action:
xoffset = int(xoldpos-getProperty("/inv", _x));
yoffset = int(getProperty("/inv", _y)-yoldpos);
if (((Number(xoffset) == 0) and (Number(yoffset) == 0)) or (not over)) {
/:xangle = (/:xangle-(/:xangle/20));
/:yangle = (/:yangle-(/:yangle/20));
} else {
/:xangle = yoffset;
/:yangle = xoffset;
}
if ((Number(/:xangle)>40)) {
/:xangle = "40";
} else if ((Number(/:xangle)
/:xangle = "-40";
}
if ((Number(/:yangle)>40)) {
/:yangle = "40";
} else if ((Number(/:yangle)
/:yangle = "-40";
}
xoldpos = getProperty("/inv", _x);
yoldpos = getProperty("/inv", _y);
在第2帧添加如下Action:
gotoAndPlay(1);
最后工作区如图6所示;
图6 工作区状态
6.最后回到主场景中,添加三个图层,从上到下分别命名为initialize, inv和Balls,在图层Inv和Balls的第4帧分别插入一个关键帧,然后从图库中将元件Inv和Balls分别拖到图层Inv和图层Balls中,同时在属性面板中分别设置其实例名为Inv和Balls,如图7所示;
图7 布置主场景
7.回到图层initialize,给第1帧添加如下Action:
xangle = "5";
yangle = "5";
在第2帧添加如下Action:
set("cos-42", 0.743144825451055);
set("cos-41", 0.754709580197564);
set("cos-40", 0.766044443094884);
set("cos-39", 0.777145961433975);
set("cos-38", 0.788010753584805);
set("cos-37", 0.798635510026434);
set("cos-36", 0.809016994355128);
set("cos-35", 0.819152044270192);
set("cos-34", 0.829037572537239);
set("cos-33", 0.838670567928596);
set("cos-32", 0.848048096140553);
set("cos-31", 0.857167300687171);
set("cos-30", 0.866025403770406);
set("cos-29", 0.874619707126247);
set("cos-28", 0.882947592846643);
set("cos-27", 0.891006524176917);
set("cos-26", 0.898794046288515);
set("cos-25", 0.906307787026791);
set("cos-24", 0.913545457633494);
set("cos-23", 0.920504853444072);
set("cos-22", 0.927183854559112);
set("cos-21", 0.933580426490206);
set("cos-20", 0.939692620779555);
set("cos-19", 0.945518575593583);
set("cos-18", 0.951056516290005);
set("cos-17", 0.956304755958442);
set("cos-16", 0.961261695934258);
set("cos-15", 0.965925826285507);
set("cos-14", 0.970295726272901);
set("cos-13", 0.974370064782571);
set("cos-12", 0.97814760073155);
set("cos-11",