Hola,
este efecto de scroll se llama "paralaje" (parallax en inglés), y la verdad es que no tiene demasiada complicación. Lo único que tienes que hacer es mover los elementos en función de la posición del ratón, pero desplazando los que están más alejados en menor proporción que los que están más cerca. Aquí te dejo un pequeño ejemplo de cómo funciona:
Código ActionScript :
var centerX:Number = Stage.width / 2;
var centerY:Number = Stage.height / 2;
var mouseX:Number;
var mouseY:Number;
var mc1:MovieClip = CreateSquare();
var mc2:MovieClip = CreateSquare();
var mc3:MovieClip = CreateSquare();
mc2._xscale = 150;
mc2._yscale = 150;
mc3._xscale = 200;
mc3._yscale = 200;
mc1._x = mc2._x = mc3._x = Stage.width / 2;
mc1._y = mc2._y = mc3._y = Stage.height / 2;
this.onMouseMove = function():Void
{
mouseX = this._xmouse - centerX;
mouseY = this._ymouse - centerY;
mc1._x = centerX + mouseX / 20;
mc1._y = centerY + mouseY / 20;
mc2._x = centerX + mouseX / 10;
mc2._y = centerY + mouseY / 10;
mc3._x = centerX + mouseX / 5;
mc3._y = centerY + mouseY / 5;
}
function CreateSquare():MovieClip
{
var depth:Number = this.getNextHighestDepth();
var mc:MovieClip = this.createEmptyMovieClip("mc" + depth, depth);
mc.lineStyle(1, 0x000000);
mc.beginFill(0xFF0000, 50);
mc.moveTo(-50, -50);
mc.lineTo(50, -50);
mc.lineTo(50, 50);
mc.lineTo(-50, 50);
mc.lineTo(-50, -50);
mc.endFill();
return mc;
}
Y si quieres que el movimiento sea más suave, puedes usar Tweens:
Código ActionScript :
import mx.transitions.Tween;
import mx.transitions.easing.*;
var centerX:Number = Stage.width / 2;
var centerY:Number = Stage.height / 2;
var mouseX:Number;
var mouseY:Number;
var mc1:MovieClip = CreateSquare();
var mc2:MovieClip = CreateSquare();
var mc3:MovieClip = CreateSquare();
mc2._xscale = 150;
mc2._yscale = 150;
mc3._xscale = 200;
mc3._yscale = 200;
mc1._x = mc2._x = mc3._x = Stage.width / 2;
mc1._y = mc2._y = mc3._y = Stage.height / 2;
this.onMouseMove = function():Void
{
mouseX = this._xmouse - centerX;
mouseY = this._ymouse - centerY;
MoveTween(mc1, centerX + mouseX / 20, centerY + mouseY / 20);
MoveTween(mc2, centerX + mouseX / 10, centerY + mouseY / 10);
MoveTween(mc3, centerX + mouseX / 5, centerY + mouseY / 5);
}
function MoveTween(mc:MovieClip, x:Number, y:Number):Void
{
var tweenX:Tween = new Tween(mc, "_x", Strong.easeOut, mc._x, x, 24, false);
var tweenY:Tween = new Tween(mc, "_y", Strong.easeOut, mc._y, y, 24, false);
}
function CreateSquare():MovieClip
{
var depth:Number = this.getNextHighestDepth();
var mc:MovieClip = this.createEmptyMovieClip("mc" + depth, depth);
mc.lineStyle(1, 0x000000);
mc.beginFill(0xFF0000, 50);
mc.moveTo(-50, -50);
mc.lineTo(50, -50);
mc.lineTo(50, 50);
mc.lineTo(-50, 50);
mc.lineTo(-50, -50);
mc.endFill();
return mc;
}