PDA

View Full Version : Translate relative coords to global



Blips
August 25th, 2008, 12:16 AM
I'm working in AS3, and I have a class that is not created at run time, but is dragged into a specific position onto the stage before publishing. This class then spawns some other MovieClips every few frames, and adds them to the stage. But I need some way of determining the spawners global position, so that the MovieClips it creates are put in the correct location. It has no knowledge of any parent movie clips that it (may) be in.

sekasi
August 25th, 2008, 01:37 AM
Have you checked out MovieClip.localToGlobal ?

Blips
August 25th, 2008, 04:53 PM
Have you checked out MovieClip.localToGlobal ?

Yes I've tried it, but it doesn't work since all I have access to is the spawner's location relative to what ever parent it may or may not be in.

senocular
August 25th, 2008, 04:56 PM
may or may not be in?

Blips
August 25th, 2008, 06:00 PM
may or may not be in?

As I said before, It's dragged onto the stage before publishing. I may drag it directly onto the stage, or embed it with in some movie clips, and put those on the stage. No matter where it is, I need to determine its global position.

senocular
August 25th, 2008, 06:05 PM
and why doesn't localToGlobal work?

Blips
August 26th, 2008, 10:40 PM
and why doesn't localToGlobal work?

As far as I know, localToGlobal requires access to the parent display container object does it not?

senocular
August 27th, 2008, 08:26 AM
yes... but you said you drag it out to somewhere, right? I think I'm just missing what the problem is.

Iamthejuggler
August 27th, 2008, 08:42 AM
If the object isn't "in" anything, then it wouldn't have global coordinates anyway.

Blips
August 27th, 2008, 06:12 PM
I realize that if it's not embedded in any other movie clips it will be in global coords, but WHEN I have it with in other objects as well, that obviously will not be the case.

"yes... but you said you drag it out to somewhere, right? I think I'm just missing what the problem is."

Yes, the spawner movie clip is a class that extends the MovieClip class. In it's constructor it's added to a "static" (using the term loosely) class that manages all of the spawner objects. Each spawner object gets run every frame, at which point they create new MovieClip objects and attaches them to the stage. While attaching them to the stage it wants to set the new MoiveClip's x/y coords to that of the spawner object. But when the spawner object is embedded in a MovieClip, those coordinates are relative to the origin of the MovieClip it's embedded within. Since the spawner object has no knowledge of it's parent, what would the simplest method of determining the spawner's global coords be?

senocular
August 27th, 2008, 07:51 PM
Since the spawner object has no knowledge of it's parent

Why wouldn't it?

Bottom line is, you have to know where you are in the hierarchy to be able to determine where you are in relation to the root of that hierarchy.