forked from: massmedian challenge
/**
* Copyright yd_niku ( http://wonderfl.net/user/yd_niku )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hCzE
*/
// forked from checkmate's massmedian challenge
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.net.*;
import flash.filters.*;
import flash.system.LoaderContext;
public class Begineer extends Sprite{
//-------------------------------//
// Use properties as follows.
//-------------------------------//
private var _sliceList:Array;
//-------------------------------//
// Change functions as follows.
//-------------------------------//
private var k:Number = 0;
public function updateEnterFrame( e:Event ):void{
var i:int = 0;
var mX:int = mouseX;// * 0.1;
var mY:int = mouseY;// * 0.1;
var pX:Number = 465/_sliceList.length;
var pY:Number = mY/ 465;
k+=5;
for each( var p:DisplayObject in _sliceList ) {
var posX:Number= ( pX * i - mX )*pY*2;
var ty:Number = -Math.abs(posX) +350;
p.y = p.y + ( ty - p.y ) * 0.2;
p.z = Math.cos( k/180*Math.PI ) * 100 + 100;
p.rotationX = k - i;
i++;
}
}
//-------------------------------//
// Do not change following codes.
//-------------------------------//
public function Begineer(){
var ctxt :LoaderContext = new LoaderContext(true);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoadComplete );
loader.load( new URLRequest("http://swf.wonderfl.net/static/assets/massmedian.png"), ctxt );
}
public function onLoadComplete(e:Event):void {
var loader:Loader = LoaderInfo( e.target ).loader;
loader.contentLoaderInfo.removeEventListener( Event.COMPLETE, onLoadComplete );
var bitmapdata:BitmapData = new BitmapData( loader.width, loader.height, true, 0xFF0000 );
bitmapdata.draw( loader );
_sliceList = sliceBanner( bitmapdata, bitmapdata.width );
addEventListener( Event.ENTER_FRAME, updateEnterFrame );
}
private function sliceBanner( banner:BitmapData, length:int = 100 ):Array{
var sliceList:Array = [];
var w:int = Math.floor( banner.width/length );
var h:int = Math.floor( banner.height );
var t:int = Math.ceil( banner.width - w*length );
var mat:Matrix = new Matrix();
for( var i:int = 0; i<length; i++ ) {
var bmpd :BitmapData = new BitmapData( w, h, true, 0xFFFF00 );
mat.tx = -w*i;
bmpd.draw( banner, mat );
var part:DisplayObject = addChild( new Bitmap( bmpd ) );
part.x = w*i;
sliceList.push( part );
}
return sliceList;
}
}
}