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

sample_01/夏勉強会

Get Adobe Flash player
by s1190163 28 Sep 2011
    Embed
/**
 * Copyright s1190163 ( http://wonderfl.net/user/s1190163 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lQqh
 */

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.sensors.Accelerometer;

    [SWF(backgroundColor = "0x00000",width="640",height="480")]
    public class sample_01 extends Sprite
    {
        private var balls:Array = new Array(); //複数のボール
        private const MAX:int = 20; //const = 定数 var = 変数

        public function sample_01()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            
                for(var i:int = 0; i< MAX; i++){
                    var ball:Ball = new Ball();
                    ball.x = Math.random()*stage.stageWidth;
                    ball.y = Math.random()*stage.stageHeight;
                    addChild(ball);
                    balls.push(ball);
                }
                
        addEventListener(Event.ENTER_FRAME,onEnterFrame);
        }
        
        private function onEnterFrame(event:Event):void
        {    
            for( var i:int=0; i<MAX; i++){
            balls[i].move();
            }
        }
    }
}

import flash.display.Sprite;

class Ball extends flash.display.Sprite
{
    public const r:int = Math.random()*30+5;
    public var vx:int = Math.random()*10+5;
    public var vy:int = Math.random()*10+5;

    public function Ball()
    {
        graphics.beginFill(Math.random()*0xFFFFFF);
        graphics.drawCircle(0,0,r);
        graphics.endFill();
    }

    public function move():void
    {
        this.x += vx;
        this.y += vy;
    
    if(this.x - r < 0){
        this.x = r;
        vx = Math.random()*10+5;
    }
    if(this.y - r < 0){
        this.y = r;
        vy = Math.random()*10+5;
    }
    if(stage.stageWidth < this.x+r){
        this.x = stage.stageWidth-r;
        vx = -(Math.random()*10+5);
    }
    if(stage.stageHeight < this.y+r){
        this.y = stage.stageHeight-r;
        vy = -(Math.random()*10+5);
    }
    }
}