flash on 2011-2-15

by yama3
♥0 | Line 74 | Modified 2011-02-15 16:05:38 | MIT License
play

ActionScript3 source code

/**
 * Copyright yama3 ( http://wonderfl.net/user/yama3 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/iQX9
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.engine.EastAsianJustifier;
    import flash.text.engine.ElementFormat;
    import flash.text.engine.FontDescription;
    import flash.text.engine.FontLookup;
    import flash.text.engine.FontPosture;
    import flash.text.engine.FontWeight;
    import flash.text.engine.LineJustification;
    import flash.text.engine.RenderingMode;
    import flash.text.engine.TextBlock;
    import flash.text.engine.TextElement;
    import flash.text.engine.TextLine;
    import flash.text.engine.TextRotation;
    import org.libspark.betweenas3.BetweenAS3;
    import org.libspark.betweenas3.tweens.ITween;
    
    [SWF(backgroundColor="0xffffff", frameRate="30", width="465", height="465")]
    
    public class FlashTest extends Sprite {
        private var txtBox:Sprite;
        private var arr:Array;
        
        public function FlashTest() {
            if(stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);            
        }
        
        private function init(e:Event=null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            txtBox = createTextBlock();
            txtBox.x = stage.stageWidth / 2;
            txtBox.y = stage.stageHeight / 2;
            addChild(txtBox);
            var tw:ITween = BetweenAS3.serial(
                BetweenAS3.delay(
                BetweenAS3.to(txtBox, {scaleX:0.5, scaleY:0.5, rotation:180}, 5), 2), BetweenAS3.to(txtBox, {y:-50}, 4));
                tw.onComplete = start;
                tw.play();
        }
        
        private function start():void {
            arr = [];
            var i:uint = 0;
            for(i = 0; i < 100; i++) {
                var sp:Sprite = createTextBlock();
                sp.x = Math.random() * 465, sp.y = 480;
                sp.rotation = 180;
                addChild(sp);
                BetweenAS3.repeat(BetweenAS3.delay(BetweenAS3.to(sp, {y:-10}, Math.random() * 7 + 5), Math.random() * 10), 100).play();
                arr[i] = sp;
            }
        }
        
        private function createTextBlock():Sprite
        {
           var font: FontDescription = new FontDescription(
                "メイリオ,ヒラギノ角ゴ Pro W3,MS Pゴシック,_ゴシック,_等幅", 
                FontWeight.BOLD, FontPosture.NORMAL, FontLookup.DEVICE, RenderingMode.NORMAL 
            );
           var format:ElementFormat = new ElementFormat(font, 24, 0x333333);
           format.locale = "ja";
           var textBlock:TextBlock = new TextBlock();
           textBlock.lineRotation = TextRotation.ROTATE_0;
           textBlock.textJustifier = new EastAsianJustifier("ja",LineJustification.UNJUSTIFIED);
           textBlock.content = new TextElement("美", format);
           var sp:Sprite = new Sprite();
           var txtLine:TextLine = textBlock.createTextLine();
           var sp:Sprite = new Sprite();
           var txtLine:TextLine = textBlock.createTextLine();
           txtLine.x = - txtLine.width / 2;
           txtLine.y = txtLine.height / 2;
           sp.addChild(txtLine);
           sp.scaleX = sp.scaleY = 0.5;
           return sp; 
        }
    }
}