forked from: TransitionEffect
// forked from yd_niku's TransitionEffect
package {
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;
import flash.net.*;
import flash.text.*;
import flash.utils.*;
import jp.progression.core.commands.*;
import jp.progression.commands.*;
import caurina.transitions.Equations;
import org.libspark.betweenas3.*;
public class MainDisplay extends Sprite {
public function MainDisplay() {
var loading :TextField = new TextField();
loading.text ="loading";
loading.width = 400;
loading.alpha = 0;
var imgurl:URLRequest= ProxyRequest.get( "http://level0.kayac.com/images/doke/oshiruko.png" );
var loader :Loader = new Loader();
var canvas:Sprite = this;
var command:CommandList = new SerialList( null,
//ローディング表示
new AddChild( this, loading ),
new DoTweener( loading, { alpha:1, time:1 } ),
// ロード開始
new LoadObject( loader, imgurl ),
// ローディング非表示
new DoTweener( loading , { alpha:0, time:1 } ),
new RemoveChild( this, loading ),
// ローディング非表示
function ():void {
var origin:BitmapData = Bitmap( loader.content ).bitmapData as BitmapData;
var mapBmp:BitmapData = new FilterMap( origin.width, origin.height );
//読み込んだ画像をエフェクトクラスに突っ込んでTweenさせる
var effect:Effect = new ThresholdEffect( origin, mapBmp );
//effect.percent = 1;
//effect.percent = 0.5;
var tx:int= ( canvas.stage.stageWidth-origin.width)*0.5;
var ty:int= ( canvas.stage.stageHeight-origin.height)*0.5;
this.parent.insertCommand(
new Prop( effect, { x:tx, y:ty } ),
new AddChild( canvas , effect ),
function():void {
BetweenAS3.serial(
BetweenAS3.tween( effect, { percent:1 }, null, 1 ),
BetweenAS3.tween( effect, { percent:0 }, null, 2 ),
BetweenAS3.tween( effect, { percent:1 }, null, 2 )
).play();
}
);
}
);
command.execute();
}
}
}
import flash.errors.IllegalOperationError;
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import flash.net.*;
import flash.system.*;
//--------------------------------------
// エフェクト本体(Templateパターン)
//--------------------------------------
class Effect extends Sprite {
private var _origin:BitmapData;
private var _output:BitmapData;
private var _effect:BitmapData;
public function Effect( origin:BitmapData, output :BitmapData = null ) {
_origin = origin;
_output = output ? output : new BitmapData( _origin.width, _origin.height, true, 0x0 );
addChild( new Bitmap( _output ) );
}
protected var _percent:Number = 0;
public function get percent():Number { return _percent; }
public function set percent(value:Number):void {
_percent = value;
_updateEffect();
}
private function _updateEffect():void{
_effect = _origin.clone();
updateEffect(_effect);
_output.fillRect( _output.rect, 0x00 );
_output.draw( _effect );
}
// ここでエフェクト処理を何かする。
protected function updateEffect( effect:BitmapData ):void{
new IllegalOperationError("updateEffectはOverrideする必要があります。");
}
}
//--------------------------------------
// エフェクト本体
//--------------------------------------
class ThresholdEffect extends Effect {
private var _mapBmp:BitmapData;
private static const START_PARAM:uint = 0x00;
private static const END_PARAM:uint = 0xFF;
public function ThresholdEffect( origin:BitmapData, mapBmp:BitmapData, output:BitmapData = null ) {
super( origin, output );
_mapBmp = mapBmp;
}
// パーセント値に応じてエフェクトをアップデート
protected override function updateEffect( effect :BitmapData ):void {
var threshold:uint = Math.round( Number( END_PARAM - START_PARAM) * _percent );
effect.threshold( _mapBmp, _mapBmp.rect, new Point(), ">=",threshold, 0x00, 0xFF );
}
}
//--------------------------------------
// エフェクト用のフィルタBitmapData
//--------------------------------------
class FilterMap extends BitmapData {
public function FilterMap( w:int, h:int ) {
super( w, h, false, 0x0 );
var map:Shape = new Shape();
var gMat:Matrix = new Matrix();
gMat.createGradientBox( w, h, -45 );
map.graphics.beginGradientFill( GradientType.LINEAR, [ 0x000000, 0xFFFFFF ], [ 1.0, 1.0 ], [ 0, 255 ], gMat );
map.graphics.drawRect( 0, 0, w, h );
map.graphics.endFill();
var rnd:int = Math.round(Math.random() * 65432);
this.perlinNoise( width/6, height/6, 24, rnd, true, true, 1, true );
draw( map, null, null, BlendMode.MULTIPLY );
}
}
//--------------------------------------
// Proxy経由のURL生成
//--------------------------------------
class ProxyRequest {
public static const PROXY:String = "http://5ivestar.org/proxy/";
public static const CROSSDOMAIN:String = "http://5ivestar.org/proxy/crossdomain.xml";
public var onComplete:Function;
public static function get( imagePath:String ) :URLRequest{
Security.loadPolicyFile(CROSSDOMAIN);
return new URLRequest( PROXY+imagePath );
}
}
//--------------------------------------
// ロードコマンド(がなぜかかなったので)
//--------------------------------------
import jp.progression.core.commands.*;
class LoadObject extends Command {
private var _loader:Loader;
private var _url:URLRequest;
public function LoadObject( loader:Loader, url:URLRequest, initObject:Object = null ){
super( _execute, _interrupt, initObject );
_loader= loader;
_url = url;
}
private function _execute():void {
//executeComplete();
_loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onLoadComplete );
_loader.load( _url );
}
private function onLoadComplete( e:Event ):void {
executeComplete();
}
private function _interrupt():void {
interruptComplete();
}
}