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

forked from: forked from: 1文字ずつ出てくる

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

// forked from Tamanegi_kenshi's forked from: 1文字ずつ出てくる
// forked from nacookan's 1文字ずつ出てくる
package {
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    import com.flashdynamix.motion.*;
    import fl.motion.easing.*;
    
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            var list:Array = getDotsList('123456789');
            var people:Array = generatePeople(5, 400)
            build(list, 0, people, 2);
            
        }
        
        private function build(list:Array, index:Number, people:Array, speed:Number):void{
            var g:TweensyGroup = new TweensyGroup();
            g.onComplete = function():void{
                index++;
                if(list.length <= index) return;
                build(list, index, people, speed);
            };
            for(var i:Number = 0; i < people.length; i++){
                var a:Number = r(list[index].length);
                g.to(people[i], {
                    x: 100 + list[index][a].x * 2, 
                    y: 100 + list[index][a].y * 2
                }, speed, Elastic.easeInOut);
            }
        }
        
        private function getDotsList(message:String):Array{
            var list:Array = [];
            for(var i:Number = 0; i < message.length; i++){
                list.push(getDots(message.substr(i, 1)));
            }
            return list;
        }
        
        private function getDots(s:String):Array{
            var f:TextFormat = new TextFormat();
            f.size = 200;
            var t:TextField = new TextField();
            t.defaultTextFormat = f;
            t.autoSize = TextFieldAutoSize.LEFT;
            t.text = s;
            var bd:BitmapData = new BitmapData(t.textWidth, t.textHeight);
            bd.draw(t);
            
            var dots:Array = [];
            for(var yy:Number = 0; yy < bd.height; yy++){
                for(var xx:Number = 0; xx < bd.width; xx++){
                    if(bd.getPixel(xx, yy) == 0xffffff) continue;
                    dots.push({ x: xx, y: yy });
                }
            }
            return dots;
        }
        
        private function generatePeople(size:Number, count:Number):Array{
            var people:Array = [];
            for(var i:Number = 0; i < count; i++){
                var person:Sprite = new Sprite();
                person.graphics.beginFill(r(0xffffff), (r(30) + 30) / 100);
                person.graphics.drawCircle(0, 0, r(size * 10) / 10);
                person.graphics.endFill();
                person.x = r(430);
                person.y = r(430);
                addChild(person);
                people.push(person);
            }
            return people;
        }
        
        private function r(max:Number):Number{
            return Math.floor(Math.random() * max);
        }
    }
}