View comments | RSS feed

MovieClip.getBounds()

Availability

Flash Player 5.

Usage

my_mc.getBounds(targetCoordinateSpace:Object) : Object

Parameters

targetCoordinateSpace The target path of the Timeline whose coordinate system you want to use as a reference point.

Returns

An object with the properties xMin, xMax, yMin, and yMax.

Description

Method; returns properties that are the minimum and maximum x and y coordinate values of the instance specified by my_mc for the targetCoordinateSpace parameter.

Note: Use MovieClip.localToGlobal() and MovieClip.globalToLocal() to convert the movie clip's local coordinates to Stage coordinates, or Stage coordinates to local coordinates, respectively.

You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see "Assigning a class to a movie clip symbol" in Using ActionScript in Flash.

Example

The following example creates a movie clip called square_mc. The code draws a square for that movie clip and uses MovieClip.getBounds() to display the coordinate values of the instance in the Output panel.

this.createEmptyMovieClip("square_mc", 1);
square_mc._x = 10;
square_mc._y = 10;
square_mc.beginFill(0xFF0000);
square_mc.moveTo(0, 0);
square_mc.lineTo(100, 0);
square_mc.lineTo(100, 100);
square_mc.lineTo(0, 100);
square_mc.lineTo(0, 0);
square_mc.endFill();

var bounds_obj:Object = square_mc.getBounds(this);
for (var i in bounds_obj) {
   trace(i+" --> "+bounds_obj[i]);
}

The following information displays in the Output panel:

yMax --> 110
yMin --> 10
xMax --> 110
xMin --> 10

See also

MovieClip.globalToLocal(), MovieClip.localToGlobal()

Comments


No screen name said on Jun 28, 2005 at 3:44 PM :
the example does not work
it never get in the for loop

??
Francis Cheng said on Jun 28, 2005 at 9:39 PM :
I just tested it again, and the code works for me. Please make sure that you have your publish settings set for ActionScript 2.0, otherwise the trace output will not appear.
isho said on Jul 2, 2005 at 11:33 PM :
Why does the object returned by getBounds() == null?

try the following code:

var bounds = _root.getBounds();

if ( bounds == null ) {
trace ( "bounds == null" );
}

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001502.html