At 7/2/07 11:56 PM, NextToNothing wrote:
** Sorry For Double Post **
Upon actually making an effort to understand I saw that you can't use _root in any way other than the functions provided... =P my bad
My question is how would putting it all in a big mc be a workaround, how could you call something inside it without still using _root ?
I'm hoping it's not to complicated or frustrating to explain but now you've pricked my curiosity and I don't see any other way to figure it out other than asking
Ok, the way you do it has to do with "hierarchy" for targeting movie clips and variables.
Basically what you're used to working with is your .swf file by itself, which means that the "_root" refers to your main timeline, in the case of WW though, your .swf will be loaded dynamically into the master WW .swf meaning that any references to "_root" will reference the WW root and not your .swf which is a "child" of _root. It's kinda like your game is a folder within the main WW folder. For folders, to go up one level you usually have to say "../", but in Actionscript you use "_parent."
So let's say you want to store a score variable, normally you'd say _root.score=0, but in this case you need to say "this.score=0"
Now, let's say you have a movieclip with instance name "dude" on your main timeline, and within "dude" at some point, you need to increase your game's score. Since "dude" is a child of your main timeline where the "score" variable is stored, you need to use correct hierarchy syntax to access that variable which would be:
this._parent.score+=1;
What this is saying is:
this (ie: "dude" since the code being executed is within dude)
._parent (the movie clip housing "dude" which is your main timeline)
.score (the variable named "score" in the main timeline)
+=1 (increase the score by one)
So it looks like this:
-->WW master .swf
--------->Your .swf main timeline (with a variable set to "score")
----------------->"dude" movieclip
Just for reference using hierarchies like this is called "relative" targeting, while using _root is called "absolute" targeting. Whenever you work on something where your .swf is child to another .swf you have to use "relative" targeting so things don't get messed up.
It's like on a webpage, if I have a folder called "images" and I'm on my index page, I can just say <img src=images/mypic.jpg> (relative targeting) but I could also say "http://www.bomtoons.com/images/mypic.jpg" (absolute targeting) in which case "the internetz" is my "_root"
So now, let's say you have another movieclip inside of "dude" called "dudette" and when dudette gets to a certain point, it needs to access the score variable on your main timeline. The syntax for that would be:
this._parent._parent.score+=1;
These "._parent"s can go on forever depending on how far down into nested movieclips you are when executing the code.
If this isn't clear check out this tutorial:
http://www.newgrounds.com/bbs/topic.php?id=38 4010
Hope that helps!