PDA

View Full Version : help understanding how to avoid using _level0 and _root


GMAN55
08-30-2007, 08:03 PM
I'm and instructional designer currently working with a program called Articulate Presenter. Articulate allows you to insert .swf files. However, their documentation states the following when optimizing Flash movies:

The general guidelines for the embedded movies follow:
* Avoid use of _level0 or absolute movie clip references. References to _root are permissible, but strongly discouraged. Use relative paths (_parent) in your movie clip references instead.

I have current movies that I created but it appears they use _level0 (which I see when I use the Debug Movie option).

My questions are:
1. How can I change my current Flash movies and republish so they don't reference or us _level0?
2. How do I avoid having my movies reference _level0 or _root when creating future Flash pieces?

I'm somewhat of a novice here - I can create some simple animations - but my action script knowledge and use is somewhat limited.

Thanks in advance,

GMAN

Noct
08-30-2007, 08:13 PM
Welcome aboard.

You see level0 in your debug movie because it is the default level Flash creates content in.
That guideline is not telling you that you shouldn't have objects at that level, it is suggesting that you don't make reference to it or "_root" in your script.

Calling _root is a common "mistake" many beginners make when they have yet to grasp the concept of a tree structure to thier project.
The issue is that _root always points to the very lowest level of your project, so if you load your swf into another swf, _root has now changed.

To avoid calling _root or level, you just make dynamic references to your objects rather then direct paths from the root of the file.

For instance, say you have two movieClips on your main stage, myMc1, and myMc2.
If you wanted to control one from the other, you could either make a path from the root:
this.myMc1.onRelease=function(){
_root.myMc2.gotoAndPlay("someFrame")
}
Or you could path backwards up the tree to get to it, which would always be correct regardless of whether or not you nested this swf in another one:
this.myMc1.onRelease=function(){
this._parent.myMc2.gotoAndPlay("someFrame")
}
It's simply saying the parent clip holding this clip has another child clip, so go down to the parent and then back up to the other child.

You can also store your paths in variables and call those instead. I will usually do that if the clip is more then two levels above the clip in question.
For instance:
var mC2:MovieClip = this.myMc2
this.myMc1.onRelease=function(){
mC2.gotoAndPlay("someFrame")
}
This becomes very handy if you have an object nested many levels deep.
Like this is a bit easier to read and follow:
var targClip:MovieClip = this.myMc.thisClip.thisOtherClip.targetClip
this.myMc2.innerClip.nestedClip2.onRelease=functio n(){
targClip._visible = false
}
Then This:

this.myMc2.innerClip.nestedClip2.onRelease=functio n(){
this._parent._parent._parent.myMc.thisClip.thisOth erClip.targetClip._visible = false
}

Make sense?

GMAN55
08-30-2007, 09:45 PM
Uhhh - I understand it somewhat - and I appreciate your help. In Articulate, when you insert your .swf files and publish the presentation, it creates a swf file and I believe the Articulate player (interface for the presentation) needs to be at level0 and that may be why they are saying not to reference it.

After looking at my files, I'm not making reference to _root or _level0 in my actionscrip. My actionscript is VERY basis for my simple movies. I'm basically using stop command to end the movie and then the on release command (attached to a Replay button) to go back to the first frame and start the movie again at frame 1 (this.gotoAndPlay("1")).

So when I run the debug - the references that I see to lines like _level0.instance9.instance10 and the like should be fine? Is there anything I should do to my basic action script to define it as a relative rather than an absolute reference usingn the Insert Target Path button in the ActionScript window?

Thanks,
GMAN

shmoo525
09-10-2007, 02:33 PM
Noct, is there a way in Flash to see a visual view of the hierarchy of all movie clips in your project? Like a tree menu or something?

Noct
09-10-2007, 02:53 PM
Yup, you can use the debugger window:
(Ctrl+Shift+Enter on PC)
Or the Movie Explorer:
(Alt+F3 on PC)
You can also see it in your actions window if you hit the "Insert a Target Path" button.

shmoo525
09-10-2007, 03:13 PM
All the debugger window says is:

_level0
_level0.instance1
_level0.instance2
_level0.instance3
_level0.instance4
...etc...

What is that supposed to mean? Shouldn't it read more like:

_level0
_level0.myClip
_level0.myNextClip
_level0.myButton
_level0.myButton.myButtonWithinAButton
_level0.myOtherButton
...etc...

In other words, why doesn't it show my actual instance names? (No, i didn't name my instances "instance1", etc...

shmoo525
09-10-2007, 03:20 PM
Oh cr*p... I *DID* name them that in this test movie I'm using. Duh! Sorry :)

shmoo525
09-10-2007, 03:38 PM
Well now, that brings me to another question, actually......

.....how do I name an instance of a movie in Actionscript? I have some MCs in another project I'm working on that are created at runtime in AS 2.0.

Noct
09-12-2007, 03:36 PM
I'm not sure I understand the question...
Anytime you create an object dynamically you have to give it an instance name.
like:
this.createEmptyMovieClip("instanceName", depth);
this.myMc.duplicateMovieClip("instanceName", depth);

You can also declare a variable reference if it helps you. You will see that used a lot in repeating functions or where the clip being created has a complex name with an incrementing variable in it. You can use the declared variable to reference the clip and apply methods/property changes:
var mc_thisClip:MovieClip = this.createEmptyMovieClip("instanceName"+varNum, varNum);
mc_thisClip._visible = false;

shmoo525
09-12-2007, 03:46 PM
Heh nevermind me :) I was running on lack of sleep and asking "duh" questions. Incidentally, your last code clip gave me another answer I was looking for ;)

shmoo525
09-12-2007, 05:33 PM
Quick question...

Are you saying you have to declare the MC as a variable in order to use variable instance names, and also to do things like set its visibility?

Noct
09-12-2007, 06:15 PM
Nope, I was just showing you that some people (my boss for instance) prefer that you call dynamically named objects by a static variable for ease of use.
Like, you could write this out like this:
for (i=0;i<5;i++){
this.myMc.createEmptyMovieClip("instanceName"+i, 50+i);
this.myMc["instanceName"+i]._visible = false;
this.myMc["instanceName"+i]._x=50
}
Or simplifiy it a bit by doing this:
for (i=0;i<5;i++){
var mc_thisClip:MovieClip = this.myMc.createEmptyMovieClip("instanceName"+i, 50+i);
mc_thisClip._visible = false;
mc_thisClip._x=50
}
They would both do the same thing, one is just a bit easier to follow/work with in some peoples opinion.
(It also creates an unneeded variable though..which is why I never did it before this job)