Показать сообщение отдельно

  #278  
Старый 26.01.2008, 23:01
Dimi4
Reservists Of Antichat - Level 6
Регистрация: 19.03.2007
Сообщений: 953
С нами: 10077446

Репутация: 3965


По умолчанию

Action Script: Имитирует падающие шарики
Код:
function fall( ) {
// Add acceleration due to gravity
this.speedY += GRAVITY;
// Reduce the speed due to friction
this.speedY *= FRICTION;
// Assume both forces work exclusively in the Y direction
this._y += this.speedY;
// Make the clip bounce up when it hits the "floor" (a line)
if (this._y > 400) {
this._y = 400;
this.speedY = -this.speedY * ELASTICITY;
}
}
function drag( ) {
// When the user clicks on a clip, make it draggable
// and stop animating it via onEnterFrame.
this.startDrag( );
delete this.onEnterFrame;
// We could save a function call by using the following:
// this.onMouseMove = updateAfterEvent;
// because the onMouseMove( ) handler calls only one function.
// However, we use the following function definition in case
// you want to add extra features, such as range checking
// to prevent clips from being dragged off stage.
this.onMouseMove = function( ) {
updateAfterEvent( );
};
}
function drop( ) {
// Initialize the drop animation and
// stop the clip being draggable.
// The initial y velocity is zero.
this.speed.y = 0;
this.stopDrag( );
this.onEnterFrame = fall;
}
// MAIN CODE
// Create 20 ball clips
for (var i = 0; i < 20; i++) {
var ball:MovieClip = this.createEmptyMovieClip("ball" + i, i);
ball.lineStyle(6, 0x0, 100);
ball.moveTo(0, -3);
ball.lineTo(1, -3);
ball._x = Math.random( ) * 550;
ball._y = Math.random( ) * 200;
ball.speedY = 0;
ball.onEnterFrame = fall;
ball.onPress = drag;
ball.onRelease = ball.onReleaseOutside = drop;
}
//Initialize physical constants
var GRAVITY:Number = 0.5;
var FRICTION:Number = 0.995;
var ELASTICITY:Number = 0.85;
// Draw the ground line
this.lineStyle(0, 0xDDDDDD, 100);
this.moveTo(0, 400);
this.lineTo(550, 400);
 
Ответить с цитированием