In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

DisplacementMapFilterを使って文字をうねうねさせる on 2010-1-30

Get Adobe Flash player
by komatsu 29 Jan 2010
    Embed
/**
 * Copyright komatsu ( http://wonderfl.net/user/komatsu )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/iGOs
 */

package {
	import flash.filters.DisplacementMapFilter;
	import flash.text.TextFormat;
	import flash.text.TextField;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    
    
    [SWF(backgroundColor="#000000", frameRate=30)]
    public class DispMapTest extends Sprite {
        public function DispMapTest() {
            var stw:uint = stage.stageWidth;
            var sth:uint = stage.stageHeight;
             
			var fillType:String = GradientType.LINEAR;
			var colors:Array = [0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000,0xFFFFFF,0x000000];
			var alphas:Array = [1,1,1,1,1,1,1];
			var ratios:Array = [0,39,91,125,168,210,255];
			var matr:Matrix = new Matrix();
			matr.createGradientBox(465,100,45*Math.PI/180,0,0);
			var spreadMethod:String = SpreadMethod.PAD;
			var sp:Sprite = new Sprite();
			sp.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);  
			sp.graphics.drawRect(0,0,465,100);
			addChild(sp);
			
			//マップをキャプチャ
			var map:BitmapData = new BitmapData(640,100);
			map.draw(sp);
			
			//テキスト用スプライト
			var tf:TextField = new TextField();
            tf.text = "Wonderfl!!";
            tf.width = stw;
            tf.y = (sth - tf.height)/2;
            tf.selectable = false;
            
            var fmt:TextFormat = new TextFormat();
            fmt.size = 80;
            fmt.align = "center";
            fmt.color = 0xFFFFFF;
            
            tf.setTextFormat(fmt)
            addChild(tf);
            
            var pnt:Point = new Point(0,0);
			
			//DisplacementMapFilter でうねうねと
			var ch:uint = BitmapDataChannel.RED;
			var filter:DisplacementMapFilter = new DisplacementMapFilter(map,pnt,ch,ch,1000,1000);
			tf.filters = new Array(filter);
			tf.alpha = 0;


			var filterTimer:Timer = new Timer(10);
			filterTimer.addEventListener(TimerEvent.TIMER , filterTimerFunc);
			function filterTimerFunc(evtObj:TimerEvent):void{
				if(tf.alpha <1){
					tf.alpha += 0.01;
				}
	
				filter.scaleX -= (filter.scaleX)/30;
				filter.scaleY -= (filter.scaleY)/30;
				tf.filters = new Array(filter);
				if(filter.scaleX<0.5){
					filter.scaleX = filter.scaleY = 0;
					tf.filters = new Array(filter);
					filterTimer.stop();
				}
			}
			filterTimer.start();
        }
    }
}