Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

getBounds method

This is a discussion on getBounds method within the Tutorials forums, part of the Flash English category; Did you notice that the new version of Actionscript has a new method: the getBounds" This method is implemented in ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 20-12-07, 06:38
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
getBounds method

Did you notice that the new version of Actionscript has a new method: the getBounds"


This method is implemented in the DisplayObject Class and so, it can be used from the MovieClip and Sprite Class (as they inherit from the DisplayObject).


The method getBounds requires a parameter named targetCoordinateSpace that indicates which DisplayObject to use and defines the coordinates to be used (local or global).
It returns an instance of Rectangle with the properties x, y, width, height, left etc, etc" of the object associated to this method.


Often, it is required to position some objects in relation to the position of some other objects and it is then necessary to do some mathematical calculi.
In this case, the method getBounds will simplify our task to do so.


Let us see how to use it"



I create a FLA and I save it as "main.fla". Into which, I create and I instantiate on stage 2 MovieClip. The first one of rectangular shape named "rect_mc" and the second one, of square shape named "square_mc".

If I wanted to position the x and y of square_mc immediately after rect_mc, I would write:
Code:
square_mc.x=rect_mc.x+rect_mc.width;
square_mc.y=rect_mc.y+rect_mc.height;
using getBounds, I could do it the following way:
Code:
var bound:Rectangle=rect_mc.getBounds(this);
square_mc.x=bound.right;
square_mc.y=bound.bottom;
and obtain the following result:






This method is really interesting when we have an application into which we need to calculate the distances of each objects in relation to the positions of some other objects. Using this method, we could simply create an instance of Rectangle with getBounds for each objects on stage and then use theirs properties left, right, top and bottom to position them.

Stay tuned !

Last edited by Flep; 28-08-08 at 06:44..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Actionscript 3.0 perlinNoise method Flep Tutorials 6 05-12-08 10:05
mailTo method Flep Tutorials 8 20-08-08 01:38
Actionscript 3 Questions on split() method.. lex_ph advanced Actionscript 3.0 1 05-08-08 19:08
getBounds - metodo di Flash CS3 Flep Articoli e tutorials 0 23-11-07 05:57
curveTo Method with Actionscript 3.0 Flep Tutorials 0 29-09-07 10:18


All times are GMT. The time now is 18:37.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap