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

震える文字

まんま震える文字。
Get Adobe Flash player
by Yuichi 16 Sep 2011
/**
 * Copyright Yuichi ( http://wonderfl.net/user/Yuichi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vc72
 */

package {
    import flash.text.TextField;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        private const size:Number = 50;//文字の大きさ
        private const texts:Vector.<String> = Vector.<String>([
            "wonderfl", "build", "flash", "online" //表示する文字列
        ]);
        private const delay:Vector.<Number> = Vector.<Number>([
            2000,       1000,    1000,    2000 //各行にかける時間(ms)
        ]);
        
        private var lines:Vector.<TextSprite> = new Vector.<TextSprite>();
        
        public function FlashTest() {
            // write as3 code here..
            if(texts.length != delay.length){
                var error:TextField = new TextField();
                error.text = "Error: texts.length != delay.length";
                error.width = error.textWidth + 4;
                error.height = error.textHeight + 4;
                addChild(error);
            }
            else{
                addEventListener(Event.ADDED_TO_STAGE, init);
                if(stage)init();
            }
        }
        
        private function init(e:Event = null):void{
            removeEventListener(Event.ADDED_TO_STAGE, init);
            
            graphics.beginFill(0xfc7f9b);
            graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            graphics.endFill();
            var i:int;
            var line:TextSprite;
            for(i = 0; i < texts.length; i++){
                line = new TextSprite(texts[i], size);
                line.baseX = (stage.stageWidth - line.width) / 2;
                line.baseY = (stage.stageHeight - line.height) / 2;
                line.x = line.baseX + 465;
                line.y = line.baseY;
                lines.push(line);
                addChild(line);
            }
            for(i = 0; i < texts.length; i++){
                lines[i].setNext(lines[(i + 1) % lines.length], delay[i]);
            }
            lines[0].start();
        }
    }
}
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.display.Sprite;
import caurina.transitions.Tweener;

class TextSprite extends Sprite{
    public var baseX:Number = 0;
    public var baseY:Number = 0;
    private var chars:Vector.<Char> = new Vector.<Char>();
    private var timer:Timer = new Timer(0, 1);
    private var next:TextSprite = null;
    private var t:int = 0;
    
    public function TextSprite(text:String = "No Text", size:Number = 20, color:uint = 0x000000){
        timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
        draw(text, size, color);
    }
    
    public function draw(text:String = "No Text", size:Number = 20, color:uint = 0x000000):void{
        //文字列をリセット
        var i:int;
        var fin:int = chars.length;
        for(i = 0; i < fin; i++){
            removeChild(chars.pop());
        }
        
        //描画に使用する変数の宣言
        var tFormat:TextFormat = new TextFormat();
        tFormat.size = size;
        tFormat.color = color;
        var tField:TextField
        tField = new TextField();
        tField.defaultTextFormat = tFormat;
        var bmpData:BitmapData;
        var bmp:Bitmap;
        var char:Char;
        var charX:Number = 0;
        
        //文字列の描画
        for(i = 0; i < text.length; i++){
            tField.text = text.charAt(i);
            tField.width = tField.textWidth + 4;
            tField.height = tField.textHeight + 4;
            char = new Char(tField);
            char.x = char.baseX = charX + char.width / 2;
            char.y = char.baseY = char.height / 2;
            charX += char.width;
            addChild(char);
            chars.push(char);
        }
    }
    
    public function setNext(next:TextSprite, delay:Number):void{
        this.next = next;
        timer.delay = delay;
    }
    
    public function start():void{
        //右から入ってくる
        x = baseX + 465;
        Tweener.addTween(this, {x:baseX, time:1});
        timer.reset();
        timer.start();
        addEventListener(Event.ENTER_FRAME, vibrate);
    }
    
    private function onTimerComplete(e:TimerEvent):void{
        //左に抜けていく
        Tweener.addTween(this, {x:baseX - 465, time:3, onComplete:function():void{
            removeEventListener(Event.ENTER_FRAME, vibrate);
        }});
        next.start();
    }
    
    private function vibrate(e:Event):void{
        //各文字を震わす
        if((t = (t + 1) % 5) == 0){
            var i:int;
            for(i = 0; i < chars.length; i++){
                chars[i].rotation = Math.random() * 10 - 5;
                chars[i].x = chars[i].baseX + Math.random() * chars[i].width / 6;
                chars[i].y = chars[i].baseY + Math.random() * chars[i].height / 6;
            }
        }
    }
}

class Char extends Sprite{
    public var baseX:Number = 0;
    public var baseY:Number = 0;
    
    public function Char(tField:TextField){
        var bmpData:BitmapData = new BitmapData(tField.width, tField.height, true, 0);
        bmpData.draw(tField);
        var bmp:Bitmap = new Bitmap(bmpData, "auto", true);
        bmp.x = -bmp.width / 2;
        bmp.y = -bmp.height / 2;
        addChild(bmp);
    }
}