ecco qua
Codice PHP:
var left:Number = 0;
var right:Number = Stage.width;
var top:Number = 0;
var bottom:Number = Stage.height;
var numBalls:Number = 8;
for(var i:Number = 0;i<numBalls;i++)
{
var ball:MovieClip = this["ball" + i];
ball.vx = Math.random() * 10 - 5;
ball.vy = Math.random() * 10 - 5;
ball._xscale = ball._yscale = ball.mass = Math.random() * 250 + 20;
}
function onEnterFrame():Void
{
for(var i=0;i<numBalls;i++)
{
var ball:MovieClip = this["ball" + i];
ball._x += ball.vx;
ball._y += ball.vy;
checkWalls(ball);
}
for(var i=0;i<numBalls-1;i++)
{
var ballA:MovieClip = this["ball" + i];
for(var j:Number = i+1;j<numBalls;j++)
{
var ballB:MovieClip = this["ball" + j];
checkCollision(ballA, ballB);
}
}
}
function checkWalls(ball:MovieClip):Void
{
if(ball._x < left + ball._width / 2)
{
ball._x = left + ball._width / 2;
ball.vx *= -1;
}
else if(ball._x > right - ball._width / 2)
{
ball._x = right - ball._width / 2;
ball.vx *= -1;
}
if(ball._y < top + ball._height / 2)
{
ball._y = top + ball._height / 2;
ball.vy *= -1;
}
else if(ball._y > bottom - ball._height / 2)
{
ball._y = bottom - ball._height / 2;
ball.vy *= -1;
}
}
function checkCollision(ball0:MovieClip, ball1:MovieClip):Void
{
var dx:Number = ball1._x - ball0._x;
var dy:Number = ball1._y - ball0._y;
var dist:Number = Math.sqrt(dx*dx + dy*dy);
if(dist < ball0._width / 2 + ball1._width / 2)
{
// calculate angle, sine and cosine
var angle:Number = Math.atan2(dy, dx);
var sine:Number = Math.sin(angle);
var cosine:Number = Math.cos(angle);
// rotate ball0's position
var pos0:Object = {x:0, y:0};
// rotate ball1's position
var pos1:Object = rotate(dx, dy, sine, cosine, true);
// rotate ball0's velocity
var vel0:Object = rotate(ball0.vx, ball0.vy, sine, cosine, true);
// rotate ball1's velocity
var vel1:Object = rotate(ball1.vx, ball1.vy, sine, cosine, true);
// collision reaction
var vxTotal:Number = vel0.x - vel1.x;
vel0.x = ((ball0.mass - ball1.mass) * vel0.x + 2 * ball1.mass * vel1.x) / (ball0.mass + ball1.mass);
vel1.x = vxTotal + vel0.x;
// update position
pos0.x += vel0.x;
pos1.x += vel1.x;
// rotate positions back
var pos0F:Object = rotate(pos0.x, pos0.y, sine, cosine, false);
var pos1F:Object = rotate(pos1.x, pos1.y, sine, cosine, false);
// adjust positions to actual screen positions
ball1._x = ball0._x + pos1F.x;
ball1._y = ball0._y + pos1F.y;
ball0._x = ball0._x + pos0F.x;
ball0._y = ball0._y + pos0F.y;
// rotate velocities back
var vel0F:Object = rotate(vel0.x, vel0.y, sine, cosine, false);
var vel1F:Object = rotate(vel1.x, vel1.y, sine, cosine, false);
ball0.vx = vel0F.x;
ball0.vy = vel0F.y;
ball1.vx = vel1F.x;
ball1.vy = vel1F.y;
}
}
function rotate(x:Number, y:Number, sine:Number, cosine:Number, reverse:Boolean):Object
{
var result:Object = new Object();
if(reverse)
{
result.x = x * cosine + y * sine;
result.y = y * cosine - x * sine;
}
else
{
result.x = x * cosine - y * sine;
result.y = y * cosine + x * sine;
}
return result;
}
ed ecco l'errore
**Errore** Scena=Scene 1, livello=Livello 22, fotogramma=1:Linea 15: È previsto '{'
function onEnterFrame():Void
**Errore** Scena=Scene 1, livello=Livello 22, fotogramma=1:Linea 35: È previsto '{'
function checkWalls(ball:MovieClip):Void
**Errore** Scena=Scene 1, livello=Livello 22, fotogramma=1:Linea 59: È previsto '{'
function checkCollision(ball0:MovieClip, ball1:MovieClip):Void
**Errore** Scena=Scene 1, livello=Livello 22, fotogramma=1:Linea 113: È previsto '{'
function rotate(x:Number, y:Number, sine:Number, cosine:Number, reverse:Boolean):Object
Totale errori ActionScript: 4 Errori segnalati: 4
se copio il fotogramma (ne è uno solo) in un filmato in cui c'è già qlkosa (qualunque filmato non uno in particolare) mi dà l'errore; se copio tutto in un filmato vuoto funge...