forked from: forked from: flash on 2011-1-1

by wexler
とりあえずなにか表示してみて、動かしてみる
Eventを使うのに必要
属性?
♥0 | Line 43 | Modified 2011-01-02 01:21:38 | MIT License
play

ActionScript3 source code

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

package {
    // とりあえずなにか表示してみて、動かしてみる
    import flash.display.Sprite;

    // Eventを使うのに必要
    import flash.events.Event;
       
    // 属性?
    [SWF(width = "200", height = "200", frameRate = "30", backgroundColor = "#FFFFFF")]

    public class FlashTest extends Sprite {
        private var pos_x:int;
        private var pos_y:int;
        private var _vx:int;
        private var _vy:int;
        private var _radius:int = 20;
        public function FlashTest() {
            graphics.beginFill(0x0000FF);
            graphics.drawCircle(20,20,20);
            graphics.endFill();

            pos_x = 100;
            pos_y = 10;
            _vx = 2;
            _vy = 0;
            
            // フレームごとに行う処理のイベントを登録            
            addEventListener(Event.ENTER_FRAME,update);
    
        }
        
        
        // フレームごとのイベント
        public function update(e:Event):void {

            _vy = _vy +1;
            
            pos_x = pos_x + _vx;
            pos_y = pos_y + _vy;
            
            if( pos_y > 200 - _radius) {
                pos_y = 200 - _radius;
                _vy = -_vy;
            }
            
            if( pos_x < 0 + _radius ) {
                pos_x = 0 + _radius;
                _vx = -_vx;
            }
            if( pos_x > 200 - _radius ) {
                pos_x = 200 - _radius;
                _vx = -_vx;
            }


            
            graphics.clear();
            graphics.beginFill(0x0000FF);
            graphics.drawCircle(pos_x,pos_y,_radius);
            graphics.endFill();
        }

    }
}