-
using _parent instead of _root - Is ONE Better than the Other?
In a number of conversations I've had with people, they've suggested using _parent rather than _root. I am not sure I fully understand the difference. Having said this, could someone apply the _parent structure to my actionscript below. I want to see if it is in fact easier to find the correct paths for my movies when they are loaded.
Code:
on (release) {
_root.siteContentPage_mc.createEmptyMovieClip("LoadLinks_mc",_root.siteContentPage_mc.getNextHighestDepth());
_root.siteContentPage_mc.LoadLinks_mc.loadMovie("../projects/Commercial/CommercialDropDown/CommercialDropDown.swf");
_root.siteContentPage_mc.LoadLinks_mc._y=17;
_root.siteContentPage_mc.LoadLinks_mc._x=0;
}
Thanks for your time ,
Greg
____________________________
Greg White
http://www.prestigeinteractive.com
-
if that code is on an MC on the main timeline, then _parent would refer to the main timeline. if it's an MC inside an MC, then _parent would refer to the "outer" MC's timeline and _parent._parent would refer to the main timeline.
_parent always refers to the object's timeline that is the next highest in the hierarchy.
so _parent is a relative reference as opposed to _root, which is absolute.
hm...i don't know if i'm coming across...just try it with some nested MCs and play around with _parent and _root.
as long as you work with one movie only, it doesn't really matter which you use. once you start loading movies dynamically, there could be problems with _root, since the use of _root in the loaded movie might be a reference to the loading movie's timeline (and not to the loaded movie's timeline, as it might have supposed to be)....
so using these two is not a question of good vs better, but rather a question of functionality.
Last edited by theTick; 02-07-2006 at 06:48 AM.
Please sign here
-
Can you give me a visual..
Hello there,
I think I understand what it is that you are talking about. Could you use the code i've typed above using _parent. I am better at figuring things out when I see them.
Thanks for your time,
Greg
____________________________
Greg White
http://www.prestigeinteractive.com
-
you see, i can only change your code, if i know how your movie is structured. is the code above on the siteContentPage_mc? or on a totally different button? is this nested inside another mc? since _parent is relative, it all depends on where the code is. if you post the fla, i can easily adjust it...
-
Monkey Moderator
When you write code that is meant to be re-used in other applications or elsewhere in the same application etc. then it often becomes necessary that all your references are relative rather than absolute. This is especially true in writing classes etc.
So in that respect it is good practice to always use relative pathing instead of absolute. It has the advantage of making your code more easily portable. I never use _root for this reason alone and is sufficient justification for it.
That said, dynamically loading movieClips that use _root should not cause a problem as you can use _lockroot. This will make all occurences of '_root' inside the loaded movie refer to the loaded movie's _root rather than the loadee movie's _root.
// i.e. inside the movieClip to be loaded...
this._lockroot = true;
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|