Bounds (class)

Categories:Geom

Overview

Summary

Creates and represents a rectangular bounding box object

Contents

Usage

Bounds objects are used in various operations in Flash, and the Bounds object provides a more object-oriented way to create bounding rectangles.

API

Bounds()

Bounds object

Parameters:

  • element Element A stage element
  • element Number A radius
  • element Array A selection
  • width Number The bounds width
  • height Number The bounds height
  • x Number The bounds x position
  • y Number The bounds y position

Returns:

  •   Object A Bounds object

The Bounds object takes a variety of arguments:

  • No arguments: Document size
  • 1 element: the element's dimensions
  • 1 number: a radius
  • 1 Array: an array of elements, bounds calculated by their extremities
  • 2 numbers: width and height
  • 4 numbers: width,height,x,y

The following example gets the bounds of the movieclips on stage, then draws a rectangle over them, and traces the bounds object:

// create the bounds object
	var elements = $(':movieclip').elements;
var bounds = new Bounds(elements); // create the rectangle
$dom.addNewPrimitiveRectangle(bounds, 0); // trace the result trace(bounds);
[object Bounds top="5" left="5" right="195" bottom="195.25"]	

Properties

top

The top of the bounds object

  • Type: Number
  • Access: Read/write

The following example creates a Bounds object that matches the stage size, then traces the top:

var bounds = new Bounds();
trace(bounds.top);
0

left

The left of the bounds object

  • Type: Number
  • Access: Read/write

The following example creates a Bounds object that matches the stage size, then traces the left side:

var bounds = new Bounds();
trace(bounds.left);
0

right

The right of the bounds object

  • Type: Number
  • Access: Read/write

The following example creates a Bounds object that matches the stage size, then traces the right side:

var bounds = new Bounds();
trace(bounds.right);
400	

bottom

The bottom of the bounds object

  • Type: Number
  • Access: Read/write

The following example creates a Bounds object that matches the stage size, then traces the bottom:

var bounds = new Bounds();
trace(bounds.bottom);
200

width

Gets the width of the Bounds object

  • Type: Number
  • Access: Read

The following example creates a Bounds object that matches the stage size, then traces the width:

var bounds = new Bounds();
trace(bounds.height);
400

height

Gets the height of the Bounds object

  • Type: Number
  • Access: Read

The following example creates a Bounds object that matches the stage size, then traces the height:

var bounds = new Bounds();
trace(bounds.height);
200

center

Gets the center of the Bounds object

  • Type: Point
  • Access: Read

The following example creates a Bounds object that matches the stage size, then traces the center, a Point object:

var bounds = new Bounds();
trace(bounds.center);
[object Point x=200 y=100]	

Methods

clone()

Returns a clone of the Bounds object

Returns:

  •   Bounds A new Bounds object

The following example creates a bounds object the same size as the stage, then duplicates it:

var bounds = new Bounds();
var bounds2 = bounds.clone();	

toString()

Returns a String representation of the Bounds object

Returns:

  •   Sting A String representation of the Bounds object

The following example traces the bounds object:

var bounds = new Bounds();
trace(bounds);
[object Bounds top="0" left="0" right="400" bottom="200"]	

Comments are closed.