flash on 2009-11-4
このサンプルはClassTestクラスがメインなので、こちらはそのまま
/**
* Copyright taketani ( http://wonderfl.net/user/taketani )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gI7G
*/
// このサンプルはClassTestクラスがメインなので、こちらはそのまま
package {
import flash.display.*;
public class ClassTest extends Sprite {
public function ClassTest() {
var width:int = this.stage.stageWidth; // ステージの幅
var height:int = this.stage.stageHeight; // ステージの高さ
for(var i:int = 0 ; i < 100 ; i++) {
var color:Number = RGBColor(255, Math.random()*256, 128+Math.random()*128);
var dt:Circle = new Circle(color);
dt.x = Math.random()*width;
dt.y = Math.random()*height;
addChild(dt);
}
}
// r,g,bの値から0xRRGGBB形式の数値を出力する関数
public function RGBColor(r:Number, g:Number, b:Number):int {
return (Math.round(r) << 16) + (Math.round(g) << 8) + Math.round(b);
}
}
}
// ClassTestおわり
// 以下はRect.asの内容の外側のpackage { } をとったもの。import文も必要
import flash.display.*;
class Rect extends Sprite { // class宣言のpublicを取る
public function Rect(color:Number) {
var shape:Shape = new Shape();
shape.graphics.lineStyle(1, 0x000000);
shape.graphics.beginFill(color);
shape.graphics.drawRect(0, 0, 50, 50);
shape.graphics.endFill();
addChild(shape);
}
}
// Rectおわり
import flash.display.*;
class Circle extends Sprite { // class宣言のpublicを取る
public function Circle(color:Number) {
var shape:Shape = new Shape();
shape.graphics.lineStyle(5,
0xFF0000,
0.4,
true,
"normal",
null,
JointStyle.ROUND,1.4);
shape.graphics.beginFill(color);
shape.graphics.moveTo(100, 10);
shape.graphics.lineTo(200, 200);
shape.graphics.lineTo(100, 200);
shape.graphics.lineTo(0, 100);
shape.graphics.drawEllipse(100, 100, 50, 50);
shape.graphics.endFill();
addChild(shape);
}
}