Flasher Archive

[Previous] [Next] - [Index] [Thread Index] - [Previous in Thread] [Next in Thread]


Subject: RE: [flasher] Levels
From: AndyA
Date: Fri, 23 Mar 2001 02:23:38 -0000

Hi Josh,

There's a difference between _level and depth. This is one of the areas
where flash's help is a little misleading in my opinion.

Leveling the playingfield
-------------------------

_level is as you describe it. It is a base timeline that is used as a
reference for everything else on that _level. Most of the time, the only
_level you will be dealing with is _level0, which is the movie you are
making, the mother and father of all timelines.

Sometimes, as you mention, you load in an swf, which is a standalone movie
all by itself. There are two ways of doing this:

loadMovieNum (which loads the movie into a _level)
loadMovie (which loads the movie into a blank MC.

loadMovieNum
------------

Until it got loaded into another movie, the newly loadMovieNum'ed swf had
its own _level0. When you load a movie in like this, things could get
confusing. Two movies in the same movie and both think they've got _level0:
a recipe for disaster! As a result, when you load an external swf in like
this, you need to give it its own _level. This acts as another base timeline
for all the stuff that goes on in the swf's timeline.

So... only when you load an external swf in with loadMovieNum, do you put it
on a _level.

When a movie is standalone, its main timeline is _root which is the same as
_level0. Everything's hunky dory.

As we said above, things get confusing with two movies in one house. Each
level has its own _root. So _level0 has a _root (which is the bottom of
_level0). _level1 also has a _root, which is the main timeline of the swf
loaded into _level1 etc etc... Each _level has its own root.

You can think of this as each SWF having a _root, but they each have a
unique name which is _levelX.

So if you are coding inside the swf on _level1, when you say _root you mean
the main timeline of the swf. When you say _level0, you mean the main
timeline of the MainMovie into which you are loaded. The same applies to
_level2.

If you are coding inside an swf loaded into _level2 and you use _root, you
mean the timeline of the swf2. When you say _level0 you mean the timeline of
the Big ole mother of all movies above. Similarly, when you want to tell the
swf on _level1 to do something, you just say _level1.goDoSomething ("Now").

loadMovie
---------

When you load an SWF into a target blank movieclip with loadMovie
("this.swf",targetMC), becomes to all intents and purposes a movieclip. It's
like the swf is pretending to be the movieclip that it was loaded into. It
answers to the same name as the movieclip, has all the same properties as
the movieclip and behaves just like that movieclip. There is one big
difference here. Because it becomes a movieclip, it is no longer allowed to
have its own _root. Only the heavy duty guys on _levels get to have their
own root. As a result, when you put code inside the swf that is loaded into
a movieclip, if you say _root then it means _level0, just like all the other
movieclips in the mother level.

Writing SWFs for loading
------------------------

As a result of the above, you can see that writing code in an swf that you
plan to load can be really difficult. Depending on where it is, how it got
there and how its going to behave, the targetting will be different. As a
general rule, it's a good idea to write your target paths as relative paths
in SWFs that you plan to load. The relative paths will always be right
whatever the situation, because they are relative to the swf. Absolute paths
(those beginnine _root or _level) will always be a bit dodgy in this
situation.

MovieClips
----------

For movieclips, something completely different happens. They are not fully
fledged movies like the SWFs. They do not have their own _root. They rely on
one of the _levels to give them a root timeline. When you duplicate a
movieclip or attach a movieclip, it is always on the same _level as the
original. When you attach a movieclip to another movieclip, they too are on
the same _level.

Unless you have loaded in an external swf, ALL the movieclips are on
_level0.

If you have attached an SWF on _level1, then ALL of the movieclips inside
that swf on are on _level1.

Depth is order
--------------

When you do duplicate movieclip though you tell it three things:

duplicateMovieClip (original to copy from, new name, Depth)

Depth here, has nothing to do with level. Depth is about Z-ordering. When
you have lots of movieclips moving around, at times they are going to
overlap. The depth setting helps flash decide which of the movies should be
on top and which of the movies should be below others. The ones on the
highest levels are always in front of the lower ones when presented on the
screen.

Sometimes, you'll want a movieclip that is up high on the top level to
suddenly go behind another movieclip lower down. This is when you use
swapDepths(). swapDepths() lets you play musical chairs with the movieclips,
so that the one you want to be on top, gets to be on top by swapping its
chair (depth) with another movieclip. Simple!

Death and Destruction
---------------------

You can only have one external swf on each _level (otherwise things would
get very confusing). The same applies for depths. If you had two movieclips
on the same depth and they overlapped, flash wouldn't know which to put in
front. As a result, Flash never lets either of these things happen.

If you try to load an swf onto the same _level as another one, flash will
kick the old one out. If you try to put one movieclip to the same Depth as
another, flash will kick the old one out.

It's that easy....

sort of

ish

Andy





[Previous] [Next] - [Index] [Thread Index] - [Next in Thread] [Previous in Thread]