Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get absolute position of clip in clip 2

Status
Not open for further replies.

firegambler

Technical User
Sep 25, 2002
455
AT
hi,

one more question...

how can i get the _y-value of a clip in relation to the main timeline?
i mean i have a clip with the path _root.menue.schieber.MChittest
it's position is always traced as 24 which is right in relation to it's parent-clip but i need the absolute position. how can i do that?

thanks in advance regards

Firegambler
 
Use localToGlobal():

(from within your clip)

pos = new Object();
pos.x =pos.y= 20;//a point 20 by 20 pixels inside the movie clip
trace('local pos is: '+pos.x+','+pos.y);//gives 20,20
this.localToGlobal(pos);
trace('global pos is: '+pos.x+','+pos.y);//gives position of point on main stage
 
sorry wangbar, i don't want to be annoying...
i don't understand this script which makes it "kind of hard".
may i tax your patience and ask you to explain it to me in detail? regards

Firegambler
 
Basically tour nested clip's y position (you say is 24) is equal to it's y position + it's parent's y position. Regards,

oldman3.gif
 
No problem - here's a step by step breakdown that will hopefully make it clearer....

What you need to do is set up a point inside your clip which you'll use to work out where this clip is on the main stage. The point is just theoretical - it doesn't actually have to be a visible graphic or anything.

Let's say our point is 0,0 - the registration point of the clip we want to find the position of.

Next we have to create an actionscript object that will hold this point's position so that we can work with it.

pos=new Object();

So we feed our point in to this object

pos.x=0;//the x coordinate we want to find
pos.y=0;//the y coordinate we want to find

Then we run this object through the conversion function:

this.localToGlobal(pos);

And pos.x and pos.y now contain the coordinates of your theoretical point as if it was on the main stage.

All of this code actually lives within the clip itself, not on the main timeline.

 
That's more or like saying the function works because the function works!

nested_pos = _root.clipa._y + _root.clipa.clipb._y;

trace ("Nested Clip's Y Position: "+nested_pos); Regards,

oldman3.gif
 
It's a line by line explanation of how the function works. How else do you suggest I describe it?
 
The maths envolved in the localToGlobal function? Regards,

oldman3.gif
 
That's like asking me to explain how the Sound object processes mp3 information in order to make the machine go beep. Why don't you ask Macromedia? I didn't write the application.

The advantage of localToGlobal over your method is that it'll work no matter how many levels deep the nested clips are; it works locally within the clip without any recourse to hardwired, therefore non-portable, level references and you don't have to know the path to the clip in order to use it.
 
Oh man :) :) ... sorry, i just had to lough a bit about your "dispute". Anyway thanks a lot for your explanation wangbar, that makes it perfectly transparent (and helps me to have an insight into this whole object-oriented-stuff).
Thanks you too,Oldnewbie for your appendix.
i may say it turned "the _alpha of my view from 90 to 100" :)

there goes a star for you guys, you're great! regards

Firegambler
 
Your last post is at least a better explanation of the advantages of using the said function...

My only point was that posting (should I say throwing at the user...) some "fancy" code that you've only come to fully understand after weeks of your own experimenting with Flash, often leaves the new user perplexed, because he has yet not reached your level of knowledge. I thought my explanation was, in that sense, a little more clearer.

Eating frozen meals may nourish you but will never teach you how to cook them! Regards,

oldman3.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top