/** * 矩形を生成 * @param x 表示座標X * @param y 表示座標Y * @param w 横幅 * @param w 縦幅 * @param color 塗りつぶし色 * @return 矩形Shape */ function createRect(x, y, w, h, color) { local rect = ::createInstance("flash.display", "Shape"); rect.graphics.lineStyle(0,color); rect.graphics.beginFill(color); rect.graphics.drawRect(0,0,w,h); rect.graphics.endFill(); rect.x = x; rect.y = y; ::getStage().addChild(rect); return rect; } /** * 円を生成 * @param x 表示座標X * @param y 表示座標Y * @param r 半径 * @param color 色 * @return 円Shape */ function createCircle(x, y, r, color) { local circle = ::createInstance("flash.display", "Shape"); circle.graphics.lineStyle(0,color); circle.graphics.beginFill(color); circle.graphics.drawCircle(0,0,r); circle.graphics.endFill(); circle.x = x; circle.y = y; ::getStage().addChild(circle); return circle; } /** * 画像を生成 * @param filename 画像ファイル名 * @return 画像 */ function createImage(filename) { local loader = ::createInstance("flash.display", "Loader"); loader.load(createInstance("flash.net", "URLRequest", filename)); return loader; } /* * ボタンを生成 * @param x 表示座標X * @param y 表示座標Y * @param image 画像ベース名 (image_o.png, image_n.png の画像を使います) * @param func 押されたとき呼ばれる関数(FlashCallerオブジェクト) */ function createButton(x, y, image, func) { local button = ::createInstance("flash.display", "SimpleButton"); // 絵を貼り付ける local over = createImage(image + "_o.png"); local normal = createImage(image + "_n.png"); button.upState = normal; button.overState = over; button.downState = over; button.hitTestState = over; // リスナー登録 button.addEventListener("mouseDown", func.getFlashFunction()); button.x = x; button.y = y; ::getStage().addChild(button); return button; } // 処理開始 print("startup!\n"); local onDown = FlashCaller(function(event) { print("button down!\n"); }); local button = createButton(200,10,"button",onDown); local rect = createRect(400,300,60,60,0xff0000); local circle = createCircle(400,300,30,0xffff00); while (true) { local tick = getCurrentTick(); rect.x = 400 + 200*sin(2 * PI * tick / 1000); circle.y = 300 + 200*sin(2 * PI * tick / 1000); suspend(); };