彩音 - Adobe AIR - 研究室:XION -Adobe AIR-laboratory
短形領域の伸縮 inflate()、inflatePoint()

inflate() は短形領域の伸縮を行う関数である。rect1 の縦横サイズを左右に15、上下に10ずつ広げる場合、rect1.inflate(15, 10)のように実行する。結果、rect1 の幅は30、高さは20広がる。新しい短形領域が生成されるのではなく、rect1自体が変更される点に注意する。

例:inflate()を使って広げる


var rect1:Rectangle = new Rectangle(50, 80, 200, 150);
rect1.inflate(15, 10);
trace(rect1);
// 出力: (x=35, y=70, w=230, h0170)

短形領域の伸縮は inflatePoint() でも行える。inflatePoint() は、左右上下に広げるサイズを Point データを使い一個の引数で指定する。

例:inflatePoint() を使い広げる


var rect1:Rectangle = new Rectangle(50, 80, 200, 150);
var size:Point = new Point(15, 10);
rect1.inflatePoint(size);
trace(rect1);
// 出力:(x=35, y=70, w=230, h=170)

例:長方形を少しずつ大きくする


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="600" height="256" initialize="init()">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
private var container:UIComponent = new UIComponent();
private function init():void {
addChild(container);
var rect:Rectangle = new Rectangle(250, 120, 20, 30);
var lineSize:uint = 3;
var lineColor:uint;
for (var i:uint = 1; i<=15; i++) {
lineColor = Math.random()*0xffffff;
container.graphics.lineStyle(lineSize, lineColor);
container.graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
rect.inflate(10, 5);
}
}
]]>
</mx:Script>
</mx:Application>

索引