forked from: ステージのサイズ取得
forked from ステージのサイズ取得 (diff: 1)
ActionScript3 source code
/**
* Copyright PAPER104 ( http://wonderfl.net/user/PAPER104 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9Y4y
*/
// forked from 0rafu0's ステージのサイズ取得
//ステージの幅と高さを取得してみました。
//あと図形描画を試したかったので色々と実験。
//マウスイベントも実験
package {
import flash.events.MouseEvent;
import flash.display.Shape;
import flash.events.Event;
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var sW:int = stage.stageWidth;
private var sH:int = stage.stageHeight;
private var shX:int = sW /10;
private var shY:int = sH /10;
private var sx:int = 0;
private var sy:int = 0;
public function FlashTest() {
var txt:TextField = new TextField();
txt.width = 400;
txt.text= "ステージ幅:"+ sW + " ステージ高さ"+sH;
addChild(txt);
stage.addEventListener(Event.ENTER_FRAME,rectMake);
stage.addEventListener(MouseEvent.MOUSE_OVER,rectStop);
}
function rectStop(e:Event){
stage.removeEventListener(Event.ENTER_FRAME,rectMake);
stage.removeEventListener(MouseEvent.MOUSE_OVER,rectStop);
stage.addEventListener(MouseEvent.MOUSE_UP,rectStart);
}
function rectStart(e:Event){
stage.addEventListener(Event.ENTER_FRAME,rectMake);
stage.addEventListener(MouseEvent.MOUSE_OVER,rectStop);
}
function rectMake(e:Event){
var sh:Shape = new Shape();
with (sh){
graphics.beginFill(Math.random() * 0xFFFFFF);
graphics.drawRect(sx,sy,shX,shY);
}
sx += shX
if (sW <= sx){
sx =0;
sy += shY;
}
if (sH <= sy){
sx = 0;
sy = 0;
}
addChild(sh);
}
}
}