forked from: 円を動かす

by uepon24 forked from 円を動かす (diff: 27)
♥0 | Line 61 | Modified 2010-03-03 01:27:00 | MIT License
play

ActionScript3 source code

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

// forked from 9re's 円を動かす
package {
    import flash.display.*;
    import flash.events.Event;
    import flash.text.TextField;

    [SWF(frameRate="30", width="465", height="465")]
    import flash.text.TextField;
    public class MyFirstAnimation extends Sprite { 
        private var _circle:Circle;
        private var _text:TextField;
        private var flagY:Boolean = true;
 
        public function MyFirstAnimation() {
            // クラスCircleのインスタンスを作る
            _circle = new Circle(10);
            // 半透明(不透明度25%)
            _circle.alpha = 0.25;
            _circle.vx = 3;
            _circle.vy = 4;
            
            // 最初の位置をwonderflの画面の中央にセット
            _circle.x = 465 / 2;
            _circle.y = 465 / 2;
            
            _text = new TextField();
            _text.width = 100;
            _text.height = 20;
            _text.x = 10;
            _text.y = 400;
            addChild(_text);
            
            // 表示リストに追加
            addChild(_circle);
 
            // 1フレーム毎に実行する処理にenterFrameHandlerを追加する
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);
        }
 
        // フレーム毎に行われる処理 [25行目で登録される]
        private function enterFrameHandler(e:Event):void {
            // 1フレーム分動かす
            _text.text = String(_circle.x);
            if(_circle.x > 465){
            		flagY = false;
            }else if(_circle.x < 0){
            		flagY = true;
	        }
            if(flagY){
            _circle.move();
            }else{
            	_circle.move2();
            }
        }
    }
}
 
import flash.display.Sprite;

class Circle extends Sprite {
    public var vx:Number;
    public var vy:Number;
    public var radius:Number;
    // コンストラクタ
    public function Circle(_radius:Number, _fillColor:uint = 0x000000) {
        // 塗り_fillColor, 半径_radiusの円
        graphics.beginFill(_fillColor);
        graphics.drawCircle(0, 0, _radius);
        graphics.endFill();
        // 半径の大きさをパブリックな変数に保存しておく
        radius = _radius
    }
    // 1フレーム分の動き
    public function move():void {
        x += vx;
        y += vy;
    }
    public function move2():void {
        x -= vx;
        y -= vy;
    }
}