Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 1 of 1

Thread: getBounds method

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,459
    Rep Power
    8

    getBounds method

    amazing Flash templates

    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.

+ Reply to Thread

Similar Threads

  1. curveTo Method with Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 1
    Last Post: 23-01-10, 17:18
  2. mailTo method
    By Flep in forum Tutorials
    Replies: 11
    Last Post: 06-01-10, 19:16
  3. New HitTest method of Actionscript 3.0
    By Flep in forum Tutorials
    Replies: 5
    Last Post: 25-08-09, 16:13
  4. fileLoaded Method
    By olicorse in forum Flash English
    Replies: 3
    Last Post: 08-04-09, 03:51
  5. getBounds - metodo di Flash CS3
    By Flep in forum Articoli e tutorials
    Replies: 0
    Last Post: 23-11-07, 05:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Optimization by vBSEO