Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 422

Programming actionscript 3.0
Table of Contents

Advertisement

Finding unions and intersections of Rectangle
objects
You use the
union()
rectangles:
import flash.display.*;
import flash.geom.Rectangle;
var rect1:Rectangle = new Rectangle(0, 0, 100, 100);
trace(rect1); // (x=0, y=0, w=100, h=100)
var rect2:Rectangle = new Rectangle(120, 60, 100, 100);
trace(rect2); // (x=120, y=60, w=100, h=100)
trace(rect1.union(rect2)); // (x=0, y=0, w=220, h=160)
You use the
intersection()
overlapping region of two rectangles:
import flash.display.*;
import flash.geom.Rectangle;
var rect1:Rectangle = new Rectangle(0, 0, 100, 100);
trace(rect1); // (x=0, y=0, w=100, h=100)
var rect2:Rectangle = new Rectangle(80, 60, 100, 100);
trace(rect2); // (x=120, y=60, w=100, h=100)
trace(rect1.intersection(rect2)); // (x=80, y=60, w=20, h=40)
You use the
intersects()
use the
intersects()
the Stage. For example, in the following code, assume that the coordinate space of the display
object container that contains the
shows how to use the
intersects specified regions of the Stage, defined by the
objects:
import flash.display.*;
import flash.geom.Rectangle;
var circle:Shape = new Shape();
circle.graphics.lineStyle(2, 0xFF0000);
circle.graphics.drawCircle(250, 250, 100);
addChild(circle);
var circleBounds:Rectangle = circle.getBounds(stage);
var target1:Rectangle = new Rectangle(0, 0, 100, 100);
trace(circleBounds.intersects(target1)); // false
var target2:Rectangle = new Rectangle(0, 0, 300, 300);
trace(circleBounds.intersects(target2)); // true
Similarly, you can use the
rectangles of two display objects overlap. You can use the
DisplayObject class to include any additional space that the strokes of a display object may
add to a bounding region.
422
Working with Geometry
method to find the rectangular region formed by the boundaries of two
method to find the rectangular region formed by the
method to find out whether two rectangles intersect. You can also
method to find out whether a display object is in a certain region of
object is the same as that of the Stage. The example
circle
method to determine if a display object,
intersects()
method to find out whether the bounding
intersects()
and
target1
target2
method of the
getRect()
,
circle
Rectangle

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents