jump to navigation

Changing the x or y coördinates of a DisplayObject in Flash CS3 September 19, 2010

Posted by Tournas Dimitrios in Flash.

The x – y properties of a DisplayObject  always refers to the position relative to the 0,0 coördinates of its parent DisplayObjectContainer 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 :

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;



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s