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 aaaaaz025 21 Jan 2011
/**
 * Copyright aaaaaz025 ( http://wonderfl.net/user/aaaaaz025 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/evo4
 */

package
{
    import flash.display.AVM1Movie;
    import flash.display.Sprite;
    import flash.events.Event;
 
    public class Main extends Sprite
    {
        private var bullet1:Bullet;
        private var bullet2:Bullet;       
 
        public function Main() 
        {            
            bullet1 = new Bullet(100, 10, 0, 0);
            addChild(bullet1);
            bullet2 = new Bullet(200, 10, 50, 50);
            addChild(bullet2);
            
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
                        
        private function onEnterFrame(event:Event):void //弾を動かす
        {
            bullet1.move();
            bullet2.move();
        }
    }
}
 
import flash.display.Sprite;
 
class Bullet extends Sprite //こっちで定義してpublic class Main extends Spriteで読み込む
{
    public function Bullet(color:int, radius:int, x:int, y:int)
    {
        graphics.beginFill(color);
        graphics.drawCircle(0, 0, radius);
        graphics.endFill();
 
        this.x = x;
        this.y = y;
    }
 
    public function move():void
    {
        this.x += 3;
        this.y += 2;
    }
}