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

[Study] AS 3.0 Animation ch10_03

Get Adobe Flash player
by nmrtmnr 12 Jul 2015
    Embed
/**
 * Copyright nmrtmnr ( http://wonderfl.net/user/nmrtmnr )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rGom
 */

package {
  import flash.display.Sprite;
  import flash.display.StageAlign;
  import flash.display.StageScaleMode;
  import flash.text.TextField;
  import flash.events.Event;
  import flash.events.MouseEvent;

  public class Rotate3 extends Sprite {
    private var balls:Array;
    private var numBalls:uint = 10;
    private var vr:Number = .05;

    public function Rotate3() {
      init();

      var textField:TextField = new TextField();
      addChild(textField);
      textField.x = 10;
      textField.y = 10;
      textField.width = stage.stageWidth;
      textField.height = 40;

      textField.text = '高度な座標回転\n複数のオブジェクトの回転(カーソルの左右の位置で速度と方向が変化)';
    }

    private function init():void {
      balls = new Array();
      for(var i:uint = 0; i < numBalls; i++){
        var ball:Ball = new Ball(20, Math.random() * 0xfffff);
        balls.push(ball);
        addChild(ball);
        ball.x = Math.random() * stage.stageWidth;
        ball.y = Math.random() * stage.stageHeight;
      }

      addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }

    private function onEnterFrame(event:Event):void {
      var angle:Number = (mouseX - stage.stageWidth / 2) * .001;
      var cos:Number = Math.cos(angle);
      var sin:Number = Math.sin(angle);

      for(var i:uint = 0; i < numBalls; i++) {
        var ball:Ball = balls[i];
        var x1:Number = ball.x - stage.stageWidth / 2;
        var y1:Number = ball.y - stage.stageHeight / 2;
        var x2:Number = cos * x1 - sin * y1;
        var y2:Number = cos * y1 + sin * x1;
        ball.x = stage.stageWidth / 2 + x2;
        ball.y = stage.stageHeight / 2 + y2;
      }
    }
  }

}

import flash.display.Sprite;

// Boxクラス
class Box extends Sprite {
  private var w:Number;
  private var h:Number;
  private var color:uint;
  public var vx:Number;
  public var vy:Number;

  public function Box(width:Number = 50, height:Number = 50, color:uint = 0xff0000) {
    w = width;
    h = height;
    this.color = color;

    init();
  }

  public function init():void {
    graphics.beginFill(color);
    graphics.drawRect(-w / 2, -h / 2, w, h);
    graphics.endFill();
  }
}
// ↑↑↑

// Arrowクラス
class Arrow extends Sprite {
  public function Arrow() {
    init();
  }

  private function init():void {
    graphics.lineStyle(1, 0, 1);
    graphics.beginFill(0xffff00);
    graphics.moveTo(-50, -25);
    graphics.lineTo(0, -25);
    graphics.lineTo(0, -50);
    graphics.lineTo(50, 0);
    graphics.lineTo(0, 50);
    graphics.lineTo(0, 25);
    graphics.lineTo(-50, 25);
    graphics.lineTo(-50, -25);
    graphics.endFill();
  }
}
// ↑↑↑

// Ballクラス
class Ball extends Sprite {
  private var radius:Number;
  private var color:uint;
  private var vx:Number = 0;
  private var vy:Number = 0;

  public function Ball(radius:Number = 40, color:uint=0xff0000) {
    this.radius = radius;
    this.color = color;
    init();
  }

  private function init():void {
    graphics.beginFill(color);
    graphics.drawCircle(0, 0, radius);
    graphics.endFill();
  }
}
// ↑↑↑