A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Find out global coordinates of a movie clip in order to animate it

  1. #1
    Member
    Join Date
    Sep 2007
    Posts
    69

    Find out global coordinates of a movie clip in order to animate it

    I have a group of movie clips (sunglass1, sunglass2, ...) arranged in rows and columns within another container movie clip. Just beside this "gallery" there's a movie clip I call frame.

    What I want to do is: when you click on a sunglassn movie clip, it has to be animated by a Tween which places it on the center of the frame from its initial location (no matter if I work with the coordinates of frame or with _root, I want to place it always on a specific location of the stage).

    For an only child, it would be something like this:

    PHP Code:
    sunglass1.onPress = function() {
         var 
    animX:Tween = new Tween(this"_x"Regular.easeInthis._xdesiredEndPointX0.5true);
         var 
    animY:Tween = new Tween(this"_y"Regular.easeInthis._ydesiredEndPointY0.5true);
    }; 
    The problem is that those coordinates are the ones in its container, not their analog ones with regard to _root or frame.

    I guess I have to use the localToGlobal method, but I don't know how to use it in this case.

    Please, could somebody help me?
    Last edited by Jazztronik; 03-12-2009 at 02:05 PM.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe you can adapt this...

    Code:
    containerMC.sunglass1.onPress = function() {
    	var myPoint:Object = {x:200, y:100};
    	this._parent.globalToLocal(myPoint);
    	var animX:Tween = new Tween(this, "_x", Regular.easeIn, this._x, myPoint.x, 0.5, true);
    	var animY:Tween = new Tween(this, "_y", Regular.easeIn, this._y, myPoint.y, 0.5, true);
    };

  3. #3
    Member
    Join Date
    Sep 2007
    Posts
    69

    Thumbs up

    Many thanks dawsonk!! I was using just the opposite method!
    Last edited by Jazztronik; 03-12-2009 at 02:39 PM.

Tags for this Thread

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center