Skip to main content
January 18, 2011
Answered

setting x and y properties according to stage.

  • January 18, 2011
  • 2 replies
  • 585 views

Hello, I need to assign a symbol that is added dynamically in a symbol, x and y coordinates (that are from the main timeline).

This topic has been closed for replies.
Correct answer Ned Murphy

Subtract the x/y coordinates of the symbol that holds the dynamically added symbol from the desired x/y coordinates (relative to the stage)...

addedMC.x = stageXDesired - parentMC.x;
addedMC.y = stageYDesired - parentMC.y;

2 replies

Inspiring
January 19, 2011

You also can read object's coordinates relative to any other object on the same display list using getBounds() or getRect().

So, to find its position relative to stage you would do something like this:

say you movie clip instance is myMC

trace(myMC.getRect(stage));

or

trace(myMC.getBounds(stage));

Here is documentation:

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#getBounds()

Also, if it is only stage that concerns you, you can use localToGlobal().

Ned Murphy
Ned MurphyCorrect answer
Legend
January 18, 2011

Subtract the x/y coordinates of the symbol that holds the dynamically added symbol from the desired x/y coordinates (relative to the stage)...

addedMC.x = stageXDesired - parentMC.x;
addedMC.y = stageYDesired - parentMC.y;