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

Flashの宝石箱やー

Get Adobe Flash player
by _wonder 05 Jan 2010

    Talk

    uwi at 05 Jan 2010 14:28
    見た目上は消えてるけどBallインスタンスはaddChildされたまんまじゃあ・・
    _wonder at 05 Jan 2010 15:10
    そうなんです!自分自身をremoveする方法がわかんなくて。 ちょっと直したんですが、これでよいのですかね・・・。
    uwi at 08 Jan 2010 12:20
    お、よさげ
    Embed
/**
 * Copyright _wonder ( http://wonderfl.net/user/_wonder )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fODG
 */

package {
    import flash.display.Sprite;
    import flash.events.*;
    
    [SWF( width="465", height="465", backgroundColor="0x000000", frameRate="30" )]
    public class Jewel extends Sprite {
        public function Jewel() {
            stage.addEventListener(Event.ENTER_FRAME, make_ball);
        }
        
        private function make_ball(e:Event):void {
            var ball:Ball = new Ball();
            ball.x = stage.mouseX;
            ball.y = stage.mouseY;
            ball.init();
            ball.move();
            addChild( ball );
        }
    }
}

import flash.display.*;
import flash.events.*;
    
internal class Ball extends Sprite {
    private var ball:Sprite;
    private var radius:Number = 5;
    private var g:Number = Math.random()+0.2;
    private var speed:Number = -10;
    private var color:int = Math.random()*0xFFFFFF;
    private var perX:Number = Math.random()*10-5;
    
    public function init():void {
        ball = new Sprite();
        ball.graphics.lineStyle(1,color);
        ball.graphics.beginFill(color,0.2);
        ball.graphics.drawCircle(0,0,5);
        ball.graphics.endFill();
        addChild( ball );
    }
    
    public function move():void {
        addEventListener(Event.ENTER_FRAME, fall);
    }
    
    public function move_stop():void {
        removeEventListener(Event.ENTER_FRAME, fall);
    }
    
    private function fall(e:Event):void {
        speed += g;
        this.y += speed;
        this.x += perX;
        if(this.y > stage.stageHeight+radius){
            move_stop();
            var parentObj:Object = Object(parent);
            parentObj.removeChild(this);
        }
    }
}