forked from: TweenMaxのよくわからない仕様シリーズ duration0がうまくいかない

by djakarta_trap forked from TweenMaxのよくわからない仕様シリーズ duration0がうまくいかない (diff: 102)
♥0 | Line 75 | Modified 2010-09-14 21:41:01 | MIT License
play

ActionScript3 source code

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

// forked from katapad's TweenMaxのよくわからない仕様シリーズ duration0がうまくいかない
package  
{
    import com.bit101.components.PushButton;
    import gs.*;
    import flash.events.MouseEvent;
    import mx.controls.Button;
    import flash.display.DisplayObject;
    import flash.display.Sprite;
    
    [SWF(width="465", height="465", backgroundColor="0xFFFFFF", frameRate="30")]
    
    public class TestTweenMax extends Sprite 
    {
        //----------------------------------
        //  static var/const
        //----------------------------------
        
        //----------------------------------
        //  instance var 
        //----------------------------------
        private var _square:DisplayObject;
        private var _normalTweenBtn:PushButton;
        private var _fixTweenBtn:PushButton;
        private var _onstartBtn:PushButton;
        private var _fromToBtn:PushButton;
        //
        /**
         * コンストラクタ
         */
        public function TestTweenMax() 
        {
            _init();
        }
        
        /**
         * 初期化
         */
        private function _init():void 
        {
            _square = addChild(new Square());
            _square.y = 250;
            _reset();
            
            _normalTweenBtn = new PushButton(this, 0, 290, 'animTime = 0 is baggy', _normalTween);
            var margin:int = _normalTweenBtn.width + 5;;
            _fixTweenBtn = new PushButton(this, margin, 290, 'animTime = 0.01...', _delayTween);
            _onstartBtn = new PushButton(this, margin * 2, 290, 'use onStart', _onstart);
            //_fromToBtn = new PushButton(this, margin * 3, 290, 'use fromto', _fromTo);
        }
        
        private function _reset():void
        {
            TweenMax.killAll();
            _square.x = 50;
        }
        private function _normalTween(event:MouseEvent):void
        {
            _reset();
            //_square.x = -20;
            TweenMax.to(_square, 1.0, { x: 100, delay: 0 });
            TweenMax.to(_square, 0.0, { x: -20, delay: 1.01, onStart:trace, onStartParams:[1] });
            TweenMax.to(_square, 1.0, { x: 200, delay: 3.02, onStart:trace, onStartParams:[2] });
        }
        
        
        private function _delayTween(event:MouseEvent):void
        {
            _reset();
            TweenMax.to(_square, 1.0, { x: 100, delay: 0 });
            TweenMax.to(_square, 0.01, { x: -20, delay: 1.01, onStart:trace, onStartParams:[1] });
            TweenMax.to(_square, 1.0, { x: 200, delay: 1.02, onStart:trace, onStartParams:[2] } );
        }
        
        private function _onstart(event:MouseEvent):void
        {
            _reset();
            TweenMax.to(_square, 1.0, { x: 100, delay: 0 });
            TweenMax.to(_square, 1.0, { x: 200, delay: 1.01, onStart: _squareMove} );
        }
        
        private function _fromTo(event:MouseEvent):void
        {
            _reset();    
            //TweenMax.to(_square, 1.0, { x: 100, delay: 0 });
            //TweenMax.fromTo(_square, 1.0, { x: -20, delay: 2}, { x: 200, delay: 1.01 } );
        }
        
        private function _squareMove():void
        {
            _square.x = -20;
        }
        
    
    }
    
}
import flash.display.Shape;
class Square extends Shape
{
    function Square(w:Number = 50, h:Number = 50, color:uint = 0, alpha:Number = 1)
    {
        graphics.beginFill(color, alpha);
        graphics.drawRect( -w * 0.5, -h * 0.5, w, h);
        graphics.endFill();
    }
    
    
}