'Super Letter Game' style control.
/**
* Copyright LawrieCape ( http://wonderfl.net/user/LawrieCape )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/fo3r
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Shape;
import flash.display.MovieClip;
public class Main extends MovieClip {
[SWF(backgroundColor=0xffffff, frameRate=50, height=750, width=750)]
public var clipWidth:int = 100;
public var numberOfBoxes:int = 200;
public var speedDivideVar:int = 2500;
public var SW:Number = stage.stageWidth;
public var SH:Number = stage.stageHeight;
public function Main():void {
makeBoxes();
}
public function makeBoxes():void{
for (var i:int = 0; i < numberOfBoxes; i++){
var box:Shape = new Shape();
var boxHolder:MovieClip = new MovieClip();
box.graphics.beginFill((0xFFFFFF/numberOfBoxes)*i);
box.graphics.drawRect(0,0,clipWidth,clipWidth);
box.graphics.endFill();
box.x = -clipWidth/2;
box.y = -clipWidth/2;
boxHolder.x = Math.random()*(SW+(clipWidth*2));
boxHolder.y = Math.random()*(SH+(clipWidth*2));
boxHolder.depth = Math.random()*100;
boxHolder.scaleX = boxHolder.scaleY = boxHolder.depth/100;
box.alpha = (boxHolder.depth/100)-0.1;
boxHolder.addChild(box);
addChild(boxHolder)
boxHolder.addEventListener(Event.ENTER_FRAME, moveBoxes);
}
}
public function moveBoxes(e:Event):void{
e.currentTarget.rotation = (e.currentTarget.x + e.currentTarget.y);
e.currentTarget.x -= (((SW/2)-mouseX)*e.currentTarget.depth)/speedDivideVar;
e.currentTarget.y -= (((SH/2)-mouseY)*e.currentTarget.depth)/speedDivideVar;
if(e.currentTarget.x<-clipWidth){
e.currentTarget.x=SW+clipWidth;
}
else if(e.currentTarget.x>SW+clipWidth){
e.currentTarget.x=-clipWidth;
}
if(e.currentTarget.y<-clipWidth){
e.currentTarget.y=SH+clipWidth;
}
else if(e.currentTarget.y>SH+clipWidth){
e.currentTarget.y=-clipWidth;
}
}
}
}