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

hearts

curveToの練習
Get Adobe Flash player
by Scmiz 14 Apr 2011
    Embed
/**
 * Copyright Scmiz ( http://wonderfl.net/user/Scmiz )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/eg1G
 */

package {
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        private var _array:Array;
        private var _frame:uint;
        
        public function FlashTest() {
            _array = new Array();
            _frame = 0; 
            
            this.graphics.beginFill(0x000000);
            this.graphics.drawRect(0, 0, 465, 465);
            this.graphics.endFill();
                       
            this.addEventListener(Event.ENTER_FRAME, proc);
        }
        
        private function proc(e:Event):void {
            ++_frame;
            if (_frame >= 2) {
                var colors:Array = new Array(0xff4040, 0x80ff80, 0x4040ff, 0xffff40, 0xffd0d0, 0x40ffff, 0xff40ff);
                var color:uint = colors[(uint)(Math.random() * colors.length)];
                
                var speedX:Number = Math.random() * 6.0 - 3.0;
                var speedY:Number = -6.0 + (Math.abs(speedX) * 0.25);

                var heart:Heart = new Heart(color, 8, speedX, speedY);
                heart.x = 232.5;
                heart.y = 200;
                this.addChildAt(heart, 0);
                _array.push(heart);   
            }
            
            for (var index:uint = 0; index < _array.length; ++index) {
                _array[index].update();
                if (_array[index].isDead) {
                    this.removeChild(_array[index]);
                    _array.splice(index, 1);
                    --index;
                    continue;
                }
            }

        }

    }
}
import flash.display.JointStyle;
import flash.display.CapsStyle;
import flash.display.LineScaleMode;
import flash.geom.Point;
import flash.display.Graphics;
import flash.display.Sprite;

class Heart extends Sprite {
    private var _speedX:Number;
    private var _speedY:Number;
    private var _isDead:Boolean;
    
    public function Heart(color:uint, size:Number, speedX:Number, speedY:Number) {
        _speedX = speedX;
        _speedY = speedY;
        _isDead = false;
        
        var g:Graphics = this.graphics;
        g.lineStyle(0, 0, 0, false, LineScaleMode.NORMAL, CapsStyle.NONE, JointStyle.ROUND);
        g.beginFill(color);
        var p0:Point = new Point(size * +0.0, size * +0.8);
        var c0:Point = new Point(size * -0.7, size * +0.8);
        var p1:Point = new Point(size * -1.0, size * -0.2);
        var c1:Point = new Point(size * -1.1, size * -0.9);
        var p2:Point = new Point(size * -0.5, size * -1.0);
        var c2:Point = new Point(size * -0.1, size * -1.0);
        var p3:Point = new Point(size * +0.0, size * -0.5);
        g.moveTo(p0.x, p0.y);
        g.curveTo(c0.x, c0.y, p1.x, p1.y);
        g.curveTo(c1.x, c1.y, p2.x, p2.y);
        g.curveTo(c2.x, c2.y, p3.x, p3.y);
        g.curveTo(-c2.x, c2.y, -p2.x, p2.y);
        g.curveTo(-c1.x, c1.y, -p1.x, p1.y);
        g.curveTo(-c0.x, c0.y, p0.x, p0.y);
        g.endFill();
    }
    
    public function get isDead():Boolean {
        return _isDead;
    }

    
    public function update():void {
        if (_isDead) return;
        
        _speedX *= 0.99;
        _speedY += 0.1;
        
        this.rotationZ += ((_speedX > 0) ? 1.0 : -1.0) * 15;
        
        this.x += _speedX;
        this.y += _speedY;
        
        if (this.y > 500) {
            _isDead = true;
        }

    }


}