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

粉砕箱

マウスをドラッグ&ドロップすると箱が飛び出すのを見るだけ。
ビットマップにしたら面白そう。
Get Adobe Flash player
by marshkip 23 Jul 2011

    Tags

    Box
    Embed
/**
 * Copyright marshkip ( http://wonderfl.net/user/marshkip )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zdTi
 */

package {
    import flash.events.Event;
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.events.MouseEvent;
    [SWF(width = "465", height = "465", frameRate = "60", backgroundColor="0xDDDFFF")]
    public class Main extends Sprite {
        public var rect:Shape;
        public var draging:Boolean;
        public function makeBox(x:Number,y:Number,vx:Number,vy:Number
        ,r:Number,color:uint):void {
            var box:Box = new Box(this,x,y,vx,vy,r,color);
            addChild(box);
        }   
        public function Main() {
            // write as3 code here..
            var bg:Sprite = new Sprite();
            bg.graphics.beginFill(0);
            bg.graphics.drawRect(0,0,465,465);
            this.addChild(bg);
            rect = new Shape;
            rect.graphics.lineStyle(0,0xFFFFFF);
            rect.graphics.drawRect(-30,-30,60,60);            
            this.addChild(rect);
            this.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
            this.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
            makeBox(10,20,5,-5,30,0xFFFFFF);            
            this.addEventListener(Event.ENTER_FRAME , onEnterFrame);
        }
        private function onEnterFrame(event:Event):void{
            if(!draging){
                rect.x = mouseX;
                rect.y = mouseY; 
            }
        }
         public function onMouseDown(event:MouseEvent):void{
            draging = true;
         }
         public function onMouseUp(event:MouseEvent):void{
            draging = false;
            makeBox(rect.x,rect.y,
            (rect.x - mouseX)*0.1,(rect.y - mouseY)*0.1,30,uint(Math.random() * 0xFFFFFF));            
         }
        
    }
}
import flash.events.Event;
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.MouseEvent;

class Box extends Sprite{
    private var vy:Number;
    private var vx:Number;
    private var vr:Number;
    private var r:Number;
    private var color:uint;
    private var pass:Main;
    private const gravity:Number = 1;
    public function Box(pas:Main , h_x:Number, h_y:Number
    , h_vx:Number , h_vy:Number , h_r:Number ,h_color:uint){
        pass = pas;
        r = h_r;
        x = h_x;
        y = h_y;
        vx = h_vx;
        vy = h_vy;
        vr = 10;
        color = h_color;
        var sh:Shape = new Shape();
        sh.graphics.beginFill(color);
        sh.graphics.drawRect(-r,-r,r*2,r*2);
        addChild(sh);
        this.addEventListener(Event.ENTER_FRAME , onEnterFrame);
    }
    private function onEnterFrame(event:Event):void{
        this.x += this.vx;
        this.y += (this.vy += this.gravity);
        this.rotation += this.vr;
        if(this.x > 465 || this.x < 0){
            x = int(x / (465)) * (465);
            this.parent.removeChild(this);
            if(r > 5){
                for(var i:int = 0 ; i < 4 ; i++)
                    this.pass.makeBox( x ,y , 
                        -vx * (Math.random()*1.5) ,
                        (vy) * (Math.random()*0.3+0.7),
                         r/(Math.random()+1.2 ),
                          color);
            }
            this.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
        }
        else if(this.y > 465 - r ){
            this.y = 465 - r;
            //vy = -vy;
            this.parent.removeChild(this);
            if(r > 5){
                for(i = 0 ; i < 4 ; i++)
                    this.pass.makeBox( x ,y , 
                        vx * (Math.random()*1.5) ,
                        (-vy) * (Math.random()*0.3+0.7),
                         r/(Math.random()*1.5 + 1 ),
                          color);
            }
            else
            {
                    
            }
            this.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
        }

    }
}