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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i get the x position of a movieclip which is in another mc?

Status
Not open for further replies.

goaganesha

Programmer
Dec 4, 2001
178
BE
Hi

I'm building a videogame like space invaders which visitors can play while waiting for the whole movie to load.

I have a movieclip (let's call it mc1) at the top of the screen which moves from left to right and goes one step down when it reaches the right or left edge. In this movieclip I have placed different movieclips (representing the bad guys (mc2,3.etc). I want to get the _x position of each of those bad guys so I can position each shot they fire right in front of that particular bad guy.

In the objectpanel of the shot I tried to use these codes:
//=======================
this._x = _root.mc2._x;
//=======================

and

//=========================
this._x = _root.mc1.mc2._x;
//=========================

but neither of them does the trick.

If I place all the bad guys within a graphic symbol, the first line of code works. But then I have to use a motion tween to let that graphic symbol move from left to right and one step down which isn't very practical.


Can anyone tell me how to get the _x position of a movieclip in another movieclip?

Thanx for your help.

Regards, Goaganesha
 
Have you tried:

_root.bad1pos = _root.mc1.mc2._x;
Etc...

Maybe use
trace(_root.bad1pos); //With expession box checked...

Regards,
wink4.gif
ldnewbie
 
Use the get property:

getProperty("_root.your_mc2.Your_mc2", _x)


where your_mc1 is the mc and Your_mc2 is the mc in the mc.

Do you understand??

Have Fun...

Sharky99 >:):O>
 
getProperty("_root.your_mc1.Your_mc2", _x)


sorry same name

Have Fun...

Sharky99 >:):O>
 
Thanx for so many replys this late at night (5.30am over here).
I'm going to bed now but I'll try it out as soon as I get up.

I'll let you guys know if it works.

regards, goaganesha
 
Sharky, getProperty is Flash 4 syntax!
Writing it as I did should work!

Regards,
wink4.gif
ldnewbie
 
Thanks OldNewbie, i heard flash4 syntax was faster??? is it true?

That's the main reason why i still use it....

Have Fun...

Sharky99 >:):O>
 
Then... Maybe it's Flash 4 you should buy in your package! LOL

Don't know how true that is regarding getProperty, but my way is certainely less typing!

Regards,
wink4.gif
ldnewbie
 
Oh! And BTW, you forgot the ";" !
_root.bad1pos = getProperty("_root.your_mc1.Your_mc2", _x);

Regards,
wink4.gif
ldnewbie
 
Thinking about it... when i learned flash5 my teacher told us about it (flash4 syntax is faster)

Maybe he didn't want to learn the flash5 syntax

That's why it's faster (for him) LOL LOL LOL

Have Fun...

Sharky99 >:):O>
 
J'vais me coucher! Grosse journée de montage demain!

Ciao!

Regards,
wink4.gif
ldnewbie
 
Merci à tous les deux!

ça marche. Moi aussi, j'ai trouvé encore une autre manière qui est
plus lentement que les vôtres et qui demande plus de programmation. ;-)

//==================================
bounds = _root.mc2.mc1.getBounds(_root);
xpos = ((bounds.xMax - bounds.xMin)/2) + bounds.xMin;
this._x = xpos
//==================================

By the way, how about my crappy French? I found it somewhere in a dark corner in the back of my brain.
It was hiding behind my crappy English. ;-)

regards, goaganesha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top