Using Rectangle Objects - Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual

Programming actionscript 3.0
Table of Contents

Advertisement

Using Rectangle objects

A Rectangle object defines a rectangular area. A Rectangle object has a position, defined by
the
and
coordinates of its top-left corner, a
property, and a
property. You
x
y
width
height
can define these properties for a new Rectangle object by invoking the
Rectangle()
constructor function, as follows:
import flash.geom.Rectangle;
var rx:Number = 0;
var ry:Number = 0;
var rwidth:Number = 100;
var rheight:Number = 50;
var rect1:Rectangle = new Rectangle(rx, ry, rwidth, rheight);
Resizing and repositioning Rectangle objects
There are a number of ways to resize and reposition Rectangle objects.
You can directly reposition the Rectangle object by changing its
and
properties. This has
x
y
no effect on the width or height of the Rectangle object.
import flash.geom.Rectangle;
var x1:Number = 0;
var y1:Number = 0;
var width1:Number = 100;
var height1:Number = 50;
var rect1:Rectangle = new Rectangle(x1, y1, width1, height1);
trace(rect1) // (x=0, y=0, w=100, h=50)
rect1.x = 20;
rect1.y = 30;
trace(rect1); // (x=20, y=30, w=100, h=50)
As the following code shows, if you change the
or
property of a Rectangle object, it
left
top
is also repositioned, with its
and
properties matching the
and
properties,
x
y
left
top
respectively. However, the position of the bottom-left corner of the Rectangle object does not
change, so it is resized.
import flash.geom.Rectangle;
var x1:Number = 0;
var y1:Number = 0;
var width1:Number = 100;
var height1:Number = 50;
var rect1:Rectangle = new Rectangle(x1, y1, width1, height1);
trace(rect1) // (x=0, y=0, w=100, h=50)
rect1.left = 20;
rect1.top = 30;
trace(rect1); // (x=30, y=20, w=70, h=30)
420
Working with Geometry

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents