静岡理工科大学 菅沼ホーム ActionScript 目次 索引

Rectangle クラス

[内容]

  矩形の座標を保持します.

継承: Rectangle → Object

[プロパティ]

[メソッド]

[使用例]

  1. Rectangle クラスの使用例」と,そのプログラム( Rectangle_e.as )です.2 つの矩形の共通領域に新しい矩形を描画しています.
    package
    {
    	import flash.display.Sprite;
    	import flash.display.Shape;
    	import flash.geom.Rectangle;
    
    	[SWF(backgroundColor="0xeeffee", width="300", height="200", frameRate="30")]
    
    	public class Rectangle_e extends Sprite
    	{
    		public function Rectangle_e()
    		{
    			init();
    		}
    		
    		private function init():void
    		{
    			var rect_p1 : Rectangle = new Rectangle(25, 25, 150, 100);
    			var rect_d1 : Shape = new Shape();
    			rect_d1.graphics.beginFill(0xff00ff00);
    			rect_d1.graphics.drawRect(rect_p1.x, rect_p1.y, rect_p1.width, rect_p1.height);
    			rect_d1.graphics.endFill();
    			addChild(rect_d1);
    
    			var rect_p2 : Rectangle = new Rectangle(125, 75, 150, 100);
    			var rect_d2 : Shape = new Shape();
    			rect_d2.graphics.beginFill(0xff00ff00);
    			rect_d2.graphics.drawRect(rect_p2.x, rect_p2.y, rect_p2.width, rect_p2.height);
    			rect_d2.graphics.endFill();
    			addChild(rect_d2);
    
    			var rect_p3 : Rectangle;
    			rect_p3 = rect_p1.intersection(rect_p2);
    			var rect_d3 : Shape = new Shape();
    			rect_d3.graphics.beginFill(0xff0000ff);
    			rect_d3.graphics.drawRect(rect_p3.x, rect_p3.y, rect_p3.width, rect_p3.height);
    			rect_d3.graphics.endFill();
    			addChild(rect_d3);
    		}
    	}
    }
    			

静岡理工科大学 菅沼ホーム ActionScript 目次 索引