DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Kalatravas has posted 29 posts at DZone. View Full User Profile

Changing The X Or Y Coördinates Of A DisplayObject In Flash CS3

09.19.2010
| 1973 views |
  • submit to reddit
        The x – y properties of a DisplayObject  always refers to the position relative to the 0,0 coördinates of its parent DisplayObject axis.
So for a movieClip instance (B) contained inside another movieClip (A)  , setting the x-y properties of “B” to zero will place it relative to the properties of the parent “A” movieClip , witch is not necessarily  the top left corner of the stage .
To position an object relative to the global stage coördinates , you can use the " globalToLocal " method of any displayObject  to convert global coördinates ( stage coördinate ) to local coördinates ( DisplayObjectContainer coördinates ) . Use the following script :
// www.tournasdimitrios1.wordpress.com

var stagePoint:Point = new Point(0 ,0) ;

var targetPoint:Point = your_DisplayObjectContainer.globalToLocal(stagePoint);

//your_DisplayObjectContainer is movieClip instance "A"

root.your_DisplayObjectContainer.your_DisplayObject.x = targePoint.x ;

//your_DisplayObject is movieClip instance "B"

root.your_DisplayObjectContainer.your_DisplayObject.y = targePoint.y ;