[study] - Tweener

by gaina
Tweener の サワリ
♥0 | Line 61 | Modified 2010-09-15 23:07:16 | MIT License
play

ActionScript3 source code

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

package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    
    /**
     * ...
     * @author gaina
     */
    public class Main extends Sprite 
    {
        
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
            for (var i:int = 0; i < 24; i++) {
                for (var j:int = 0; j < 20; j++) {
                    var _text:TextAnimationTest = new TextAnimationTest("text");
                    _text.x = 10 + j*_text.width;
                    _text.y = -15 + i*_text.height;
                    addChild(_text);
                    _text.animation(j * 0.1 +i * 1);
                }
            }
        }
        
    }
    
}

import flash.events.MouseEvent;
import flash.text.TextField;
import caurina.transitions.Tweener;

class TextAnimationTest extends TextField
{
    
    private var originalPositionX:Number = 0;
    private var originalPositionY:Number = 0;
    
    public function TextAnimationTest(_str:String="")
    {
        this.text = _str;
        this.autoSize = "left";
    }
    
    private function MouseOutEvent(e:MouseEvent):void 
    {
        Tweener.addTween(this, { x:originalPositionX, y:originalPositionY, time:0.5 } );
    }
    
    private function MouseOverEvent(e:MouseEvent):void 
    {
        Tweener.addTween(this, { y:this.y+15, time:0.5 } );
    }
    
    public function animation(_delay:Number):void
    {
        var _x:Number = this.x;
        var _y:Number = this.y + this.height;
        this.alpha = 0;
        Tweener.addTween(this, { y:_y, alpha:1, time:1, delay:_delay, onComplete:CompleteEvent } );
        originalPositionX = this.x;
        originalPositionY = _y;
    }
    
    private function CompleteEvent():void
    {
        this.addEventListener(MouseEvent.MOUSE_OVER, MouseOverEvent);
        this.addEventListener(MouseEvent.MOUSE_OUT, MouseOutEvent);
    }
    
}