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: AtoZ Typing

結果をツイートできる様にしました。
/**
 * Copyright matacat ( http://wonderfl.net/user/matacat )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/iZKm
 */

// forked from h6k's forked from: AtoZ Typing
// forked from h6k's AtoZ Typing
// 結果をツイートできる様にしました。
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;
    import flash.net.navigateToURL;
    import flash.utils.getTimer;
    
    import com.bit101.components.PushButton;
    
    [SWF(frameRate = 60)]
    
    public class FlashTest extends Sprite
    {
        private var startTime:int;
        private var scoreTime:int;
        private var currentChar:int;
        
        private var az:Vector.<Letter>;
        private var frame:Frame;
        private var timeDisp:AutoTF;
        private var tweetBtn:PushButton;
        private var btnFrame:Frame;
        
        public function FlashTest()
        {
            var wz:int = stage.stageWidth;
            var hi:int = stage.stageHeight;
            
            Letter.setCenter(wz / 2, hi / 2);
            
            az = new Vector.<Letter>(26);
            for (var i:int = 0; i < 26; i++) {
                az[i] = addChild(new Letter(i)) as Letter;
            }
            
            frame = new Frame(stage, az[22]);
            
            var tf:AutoTF = new AutoTF(stage, "Push Space Key to Restart");
            tf.y = hi / 2 - tf.height * 2;
            
            timeDisp = new AutoTF(stage, "0000.000 sec", true);
            timeDisp.y        = tf.y + tf.height + 5;
            timeDisp.autoSize = "none";
            
            tweetBtn = new PushButton(stage, 0, 0, "Click here to tweet your score!", tweet);
            tweetBtn.width += 50;
            tweetBtn.x      = (wz - tweetBtn.width) / 2 ;
            tweetBtn.y      = timeDisp.y + timeDisp.height + 15;
            
            btnFrame = new Frame(stage, tweetBtn);
            
            reset();
            
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
        }
        
        private function reset():void
        {
            currentChar   = 65;
            
            timeDisp.text = "0.000 sec";
            
            for (var i:int = 0; i < 26; i++) {
                az[i].reset();
            }
            frame.appear();
            
            tweetBtn.visible = false;
            btnFrame.disappear();
        }
        
        private function onKeyDown(e:KeyboardEvent):void
        {
            var kc:int = e.keyCode;
            
            if (kc > 90 || kc < 65 && kc != 32) return;
            
            if(kc == currentChar) {
                if (kc == 65) {
                    startTime = getTimer();
                    stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
                    
                } else if (kc == 90) {
                    stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
                    onEnterFrame(null);
                    frame.disappear();
                    tweetBtn.visible = true;
                    btnFrame.appear();
                }
                
                currentChar++;
                for (var i:int = 0; i < 26; i++) {
                    az[i].goNext();
                }
                
            } else if (kc == 32) {
                stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
                reset();
            }
        }
        
        private function onEnterFrame(e:Event):void
        {
            scoreTime     = getTimer() - startTime;
            timeDisp.text = (scoreTime / 1000).toFixed(3) + " sec";
        }
        
        private function tweet(e:MouseEvent):void
        {
            var url:String
            = "http://twitter.com/home?status="
            + encodeURIComponent(
                "AtoZ Typing の結果: " +
                (scoreTime / 1000).toFixed(3) +
                "sec. http://wonderfl.net/c/iZKm/ #wonderfl"
            );
            navigateToURL(new URLRequest(url));
        }
    }
}


import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Shape;
import flash.filters.GlowFilter;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.text.TextFormat;

import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.Quad;
import org.libspark.betweenas3.easing.Sine;
import org.libspark.betweenas3.tweens.ITween;

class Letter extends Bitmap
{
    //////////////////////
    //  static members  //
    //////////////////////
    
    private static const PI2:Number = Math.PI / 180;
    private static const R:Number   = 220;
    
    private static var centerX:Number;
    private static var centerY:Number;
    public static function setCenter(cX:Number, cY:Number):void
    {
        centerX = cX;
        centerY = cY;
    }
    
    // 使い回し用
    private static var tf:TextField = new TextField();
    tf.defaultTextFormat = new TextFormat(null, 50);
    tf.autoSize          = "left";
    
    
    ////////////////////////
    //  instance members  //
    ////////////////////////
    
    private var life:int;
    private var maxL:int;
    private var resetMotion:ITween;
    
    public function Letter(index:int):void
    {
        tf.text = String.fromCharCode(index + 65);
        super(new BitmapData(tf.width, tf.height, true, 0));
        bitmapData.draw(tf);
        
        smoothing = true;
        alpha     = 0;
        degree    = 0;
        life      = index;
        maxL      = index;
        
        resetMotion = BetweenAS3.delay(
            BetweenAS3.tween(
                this,
                { alpha: 1, degree: 360 * index / 26 },
                { alpha: 0, degree: 0 },
                0.5,
                Quad.easeOut
            ), 1 - index / 26
        );
    }
    
    public function goNext():void
    {
        life--;
        if (life >= 0) {
            BetweenAS3.to(this, { degree: 360 * life / 26 }, 0.25, Quad.easeOut).play();
        } else if (life == -1) {
            BetweenAS3.to(this, { alpha: 0, degree: -15 }, 1, Quad.easeOut).play();
        }
    }
    
    public function reset():void
    {
        life = maxL;
        resetMotion.play();
    }
    
    private var _deg:Number;
    public function get degree():Number { return _deg; }
    public function set degree(d:Number):void
    {
        _deg = d;
        var cos:Number = Math.cos(d * PI2);
        var scl:Number = (cos + 1) * 0.35 + 0.3;
        scaleX = scl;
        scaleY = scl;
        x      = R * Math.sin(d * PI2) + centerX - width / 2;
        y      = R * cos * 0.5         + centerY - height / 2;
    }
}

class AutoTF extends TextField
{
    private static var form:TextFormat = new TextFormat();
    form.align = "right";
    
    public function AutoTF(dest:DisplayObjectContainer, text:String, bg:Boolean = false)
    {
        super();
        dest.addChild(this);
        
        defaultTextFormat = form;
        autoSize          = "right";
        this.text         = text;
        mouseEnabled      = false;
        x                 = (stage.stageWidth - width) / 2;
        
        if (bg) {
            border          = true;
            background      = true;
            backgroundColor = 0;
            textColor       = 0xFFFFFF;
        }
    }
}

class Frame extends Shape
{
    private var blink:ITween;
    private var fadeIn:ITween;
    
    public function Frame(dest:DisplayObjectContainer, target:DisplayObject)
    {
        super();
        
        var wz:Number = target.width;
        var hi:Number = target.height;
        
        graphics.beginFill(0);
        graphics.drawRect(wz / -2, hi / -2, wz, hi);
        
        x       = target.x + wz / 2;
        y       = target.y + hi / 2;
        alpha   = 0;
        filters = [new GlowFilter(0x8080FF, 1, 16, 16, 1, 1, false, true)];
        
        var b:ITween = BetweenAS3.tween(this, { alpha: 0.5 }, { alpha: 1 }, 0.5, Sine.easeInOut);
        
        blink = BetweenAS3.serial(b, BetweenAS3.reverse(b));
        blink.stopOnComplete = false;
        
        fadeIn = BetweenAS3.tween(
            this,
            { scaleX: 1,   scaleY: 1,   alpha: 1 },
            { scaleX: 1.5, scaleY: 1.5, alpha: 0 },
            1,
            Quad.easeOut
        );
        fadeIn.onComplete = blink.play;
        
        dest.addChild(this);
    }
    
    public function appear():void
    {
        blink.gotoAndStop(0);
        fadeIn.play();
    }
    
    public function disappear():void
    {
        blink.stop();
        BetweenAS3.to(this, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, 0.5, Quad.easeIn).play();
    }
}