parallax
/**
* Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/6gP3
*/
// BradSedito 2011
package {
import flash.display.MovieClip;
import flash.display.BlendMode;
import flash.events.Event;
import gs.*;
import gs.easing.*;
[SWF(frameRate = '100', backgroundColor='0xffffff')]
public class FlashTest extends MovieClip {
private var scx:Number;
private var scy:Number;
private var back:MovieClip
private var front:MovieClip
public function FlashTest() {
// constructor code
var mesh:Mesh;
// TweenMax.to(back, .5, {tint:0x333333});
// front.BlendMode = BlendMode.ADD;
// back.BlendMode = BlendMode.INVERT;
scx=stage.stageWidth*.5;
scy=stage.stageHeight*.5;
//
back=new MovieClip();
back.x=scx;
back.y=scy;
back.lx=scx;
back.ly=scy;
mesh=new Mesh();
mesh.x=mesh.width*-.5
mesh.y=mesh.height*-.5
back.addChild(mesh)
addChild(back);
//
front=new MovieClip();
front.x=scx;
front.y=scy;
front.lx=scx;
front.ly=scy;
mesh=new Mesh()
mesh.scaleX=0.9;
mesh.scaleY=mesh.scaleX;
mesh.x=mesh.width*-.5;
mesh.y=mesh.height*-.5;
front.addChild(mesh)
addChild(front);
addEventListener(Event.ENTER_FRAME,ent);
front.addEventListener(Event.ENTER_FRAME,mesh_ent)
back.addEventListener(Event.ENTER_FRAME,mesh_ent)
}
//
private function ent(evt:Event):void{
var dsx:Number=-90*(scx-mouseX)/(0.5*stage.stageWidth);
var dsy:Number=-90*(scx-mouseY)/(0.5*stage.stageHeight);
front.lx=scx+dsx;
front.ly=scy+dsy;
back.lx=scx+dsx*0.3;
back.ly=scy+dsy*0.3;
}
private function mesh_ent(evt:Event):void{
var _mc:MovieClip=evt.currentTarget as MovieClip;
var dx:Number=0.1*(_mc.lx-_mc.x)
var dy:Number=0.1*(_mc.ly-_mc.y);
_mc.x+=dx;
_mc.y+=dy;
}
}
}
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Graphics;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.BlendMode;
class Mesh extends MovieClip {
public function Mesh() {
var i:uint;
var j:uint;
var k:uint;
var shape:Sprite=new Sprite()
for(k=0;k<30;k++){
for(j=0;j<15;j++){
for(i=0;i<10;i++){
var g:Graphics=shape.graphics;
g.lineStyle(5,0x555555);
g.moveTo(30*(k%2)+60*j+3*i,30*k+0);
g.lineTo(30*(k%2)+60*j+3*i,30*k+30);
g.lineStyle.apply(alpha=.7);
g.endFill();
}
}
}
var bmd:BitmapData=new BitmapData(shape.width,shape.height,true,0xFFFF);
bmd.draw(shape)
var bm:Bitmap=new Bitmap(bmd)
addChild(bm);
}
}