图1.4 鼠标制作
5.新建一影片剪辑“animation”,将默认图层命名为“animation”,“ animation”只有一个图层,同时只有四帧。下面将分别为这四个关键帧进行相应设置
选中第1关键帧,添加如下actionscript脚本代码:
// creazione della classe puntospaziale
function puntospaziale (x, y, z, target) {
// propriet?
this.target = target;
this.x = x;
this.y = y;
this.z = z;
this.firstx = x;
this.firsty = y;
this.firstz = z;
this.dfowa = 100;
// distance from object world axes
this.dfpp = 200;
// distance from proiection plain
this.screencenter_x = 300;
this.screencenter_y = 200;
this.speed2dx = 0;
this.speed2dy = 0;
// metodi
this.coord2drelativeto = coord2drelativeto;
this.coord3drelativeto = coord3drelativeto;
this.rotate = rotate;
this.scale = scale;
this.uscale = uscale;
this.traslate = traslate;
this.proiection_y = proiection_y;
this.proiection_x = proiection_x;
this.drawpoint = drawpoint;
// funzioni che definiscono i metodi
function coord3drelativeto (x1, y1, z1) {
// cambio di coordinate 3d in riferimento ad un'altro punto
this.x -= x1;
this.y -= y2;
this.z -= z3;
}
function coord2drelativeto (x, y) {
// cambio di coordinate "d di proiezione in riferimento ad un'altro punto
// per esempio si pu?usare per centrare il punto (0,0) al centro dello schermo
// ( in tal caso passare come parametri le coordinate di tale centro )
this.screencenter_x = x;
this.screencenter_y = y;
}
function rotate (teta_x, teta_y, teta_z) {
// rotazione intorno agli assi x, y e z espressa in radianti
if (teta_x != 0) {
ytemp = this.y;
this.y = this.y*math.cos(teta_x)-this.z*math.sin(teta_x);
this.z = ytemp*math.sin(teta_x)+this.z*math.cos(teta_x);
}
if (teta_y != 0) {
xtemp = this.x;
this.x = this.x*math.cos(teta_y)+this.z*math.sin(teta_y);
this.z = this.z*math.cos(teta_y)-xtemp*math.sin(teta_y);
}
if (teta_z != 0) {
xtemp = this.x;
this.x = this.x*math.cos(teta_z)-this.y*math.sin(teta_z);
this.y = this.y*math.cos(teta_z)+xtemp*math.sin(teta_z);
}
}
function scale (sx, sy, sz) {
// scalamento non uniforme
this.x *= sx;
this.y *= sy;
this.z *= sx;
}
function uscale (s) {
// scalamento uniforme
this.x *= s;
this.y *= s;
this.z *= s;
}
function traslate (a, b, c) {
// traslazione
this.x += a;
this.y += b;
this.z += c;
}
function drawpoint (i) {
// caratterrizza il nome e la profondit?dell'istanza duplicata
duplicatemovieclip (this.target, "punto"+i, i);
mymovieclip = eval("punto"+i);
setproperty ("punto"+i, _x, this.proiection_x());
setproperty ("punto"+i, _y, this.proiection_y());
setproperty ("punto"+i, _xscale, (100/(((this.z+this.dfowa)/this.dfpp)+1)));
setproperty ("punto"+i, _yscale, (100/(((this.z+this.dfowa)/this.dfpp)+1)));
mycolor = new color(eval("punto"+i));
mycolortransform = new object();
s = (this.z+50)/1;
mycolortransform = {ra:'100', rb:-s, ga:'100', gb:-s, ba:'100', bb:-s, aa:'100', ab:'0'};
mycolor.settransform(mycolortransform);
}
function proiection_x () {
// coordinata x della proiezione
this.proiectionx = (this.x/(((this.z+this.dfowa)/this.dfpp)+1)+this.screencenter_x);
return (this.x/(((this.z+this.dfowa)/this.dfpp)+1)+this.screencenter_x);
}
function proiection_y () {
// coordinata y della proiezione
this.proiectiony = (this.y/(((this.z+this.dfowa)/this.dfpp)+1)+this.screencenter_y);
return (this.y/(((this.z+this.dfowa)/this.dfpp)+1)+this.screencenter_y);
}
}
// funzione che prende un array di valori numerici e restituisce un
// array delle stesse dimensioni contenente nella prima posizione
// il numero ordinele che indica a che posto ?il primo elemento
// dell'array input quanto a grandezza
// per esempio se il primo elemento ?il pi?grande allora nell'array
// restituito avr?1 nella prima pos. se ?il quarto pi?grande avr?
// 4 etc.....
// nel caso di due elementi coincidenti l'indice relativo sar?comunque diverso secondo un criterio casuale
function ordindex (inputarray) {
len = inputarray.length;
for (var e = 0; e inputarray[e] = inputarray[e]+math.random()/100000000;
}
index = new array(len);
for (var i = 0; i var count = 0;
for (var j = 0; j if (inputarray<=inputarray[j]) {
count++;
}
}
index = count;
}
return index;
}
选中第2关键帧,添加如下actionscript脚本代码:
xrotation = 0;
yrotation = 0;
xposition = 0;
yposition = 0;
depth = 0;
var miopunto1 = new puntospaziale(0, -25, 50, "point");
var miopunto2 = new puntospaziale(-43.3, -25, -25, "point");
var miopunto3 = new puntospaziale(43.3, -25, -25, "point");
var miopunto4 = new puntospaziale(0, 43.3, 0, "point");
var miopunto5 = new puntospaziale(0, 0, 0, "cursor");
mouse.hide();
选中第3关键帧,从库面板中将“sphere”和“coursor”插入工作区中,创建相应的实例,并分别为其实例命名为“point”和“sphere”,为第3关键帧添加如下actionscript 脚本:
xrotation = 0.05-(yposition-_ymouse)/400-xrotation/5;
yrotation = (xposition-_xmouse)/400-xrotation/5+0.05;
zrotation = 0.05;
for (var i = 1; i<5; i++) {
eval("miopunto"+i).rotate(xrotation, yrotation, zrotation);
eval("miopunto"+i).speed2dx += (_xmouse-eval("miopunto"+i).screencenter_x)/100-eval("miopunto"+i).speed2dx/10;
eval("miopunto"+i).speed2dy += (_ymouse-eval("miopunto"+i).screencenter_y)/100-eval("miopunto"+i).speed2dy/10;
xposition += eval("miopunto"+i).speed2dx;
yposition += eval("miopunto"+i).speed2dy;
eval("miopunto"+i).coord2drelativeto(xposition, yposition);
}
miopunto5.x = _xmouse*1.5-450;
miopunto5.y = _ymouse*1.5-300;
deptharray = new array(5);
for (var k = 1; k<=5; k++) {
deptharray[k-1] = eval("miopunto"+k).z;
}
indexdepht = ordindex(deptharray);
for (var f = 1; f<=5; f++) {
eval("miopunto"+f).drawpoint(indexdepht[f-1]);
}
选中第4关键帧,添加如下actionscript脚本代码:
gotoandplay(3);
6.返回主场景并将默认图层更名为“电影剪辑”,将“animation”插入工作区中,将建一图层“背景”,作矩形工具绘制一矩形,使其将整个工作区复盖,通过“混色器”面板将设置其填充色如图1.5所示: