Aqui la clase encargada de crear la magia, esta case debe estar relacionada directamente con un MovieClip. si alguien tiene alguna duda, puede hacermelo saber. reduje las funciones, optimice un poco.
Código :
import flash.geom.Point; class Cuadrado extends MovieClip { public static var limiteSuperior:Number = 0; public static var limiteInferior:Number = 200; public static var limiteIzquierda:Number = 0; public static var limiteDerecha:Number = 200; public static var espaciado:Number = 8; public static var velocidad:Number = 8; public static var radio:Number = 150; public var _x2:Number; public var _y2:Number; public function Cuadrado () { super(); //Si es el primero if( this._x2 == undefined && this._y2 == undefined ) { this._x2 = 0; this._y2 = 0; this.swapDepths(1) } this._name = "X" + this._x2 + "Y" + this._y2; this._alpha = 0; } private function onEnterFrame (Void) { //Si estoy fuera del limite if( !this.dentro() ) { this.removeMovieClip(); return; } var center:Point = new Point( 0, 0 ) center.y = Math.abs(limiteInferior - limiteSuperior) / 2; center.x = Math.abs(limiteDerecha - limiteIzquierda) / 2; var cords:Point = new Point( this._x, this._y ); this._parent.localToGlobal( cords ); var mouse:Point = new Point( _root._xmouse, _root._ymouse ); var dist:Number = Math.floor(Point.distance( mouse, cords )); this._alpha += ( Math.max(radio - dist, 0) - this._alpha ) / velocidad; this._x -= Math.max( -100, Math.min( 100, mouse.x - center.x ) ) / velocidad; this._y -= Math.max( -100, Math.min( 100, mouse.y - center.y ) ) / velocidad; var objetos:Array = new Array(); //Arriba objetos[0] = { _x2:(this._x2), _y2:( this._y2 + 1) }; //Abajo objetos[1] = { _x2:(this._x2), _y2:( this._y2 - 1) }; //Adelante objetos[2] = { _x2:(this._x2 + 1), _y2:( this._y2 ) }; //Atras objetos[3] = { _x2:(this._x2 - 1), _y2:( this._y2 ) }; for( var i:Number = 0; i <= 3; i++ ) { objetos[i]._name = "X" + objetos[i]._x2 + "Y" + objetos[i]._y2; objetos[i]._alpha = this._alpha; //Si no existe ese objeto if( this._parent[ objetos[i]._name ] == undefined ) { objetos[i]._x = this._x + ( (this._width + espaciado) * ( this._x2 - objetos[i]._x2 ) ) objetos[i]._y = this._y + ( (this._height + espaciado) * ( this._y2 - objetos[i]._y2 ) ) if( this.adentro( objetos[i]._x , objetos[i]._y ) ) { this._parent.attachMovie( "Cuadrado", objetos[i]._name, this._parent.getNextHighestDepth(), objetos[i]); } } } } private function dentro( Void ):Boolean { var aux:Object = this.getBounds( _root ); return aux.yMax > limiteSuperior && aux.yMin < limiteInferior && aux.xMax > limiteIzquierda && aux.xMin < limiteDerecha; } private function adentro( x:Number, y:Number ):Boolean { var aux:Object = {x:x, y:y}; this._parent.localToGlobal( aux ); aux.yMax = aux.y + this._height; aux.yMin = aux.y; aux.xMax = aux.x + this._width; aux.xMin = aux.x; return aux.yMax > limiteSuperior && aux.yMin < limiteInferior && aux.xMax > limiteIzquierda && aux.xMin < limiteDerecha; } }