English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Is there a way to check the current level a movie is load in, in flash? i couldn't find any actionscript on it...

something like if(_level.current==1) in theory?

2007-03-26 01:14:16 · 2 answers · asked by dj_stokes 2 in Computers & Internet Programming & Design

2 answers

You couldn't find any actionscript reference to it, simply because its much easier than you think - and far easier than the last answerer tried to make out.

Simply put, the level you are on is "this".

The top level is "_level0".

The levels below level0 are the instance names that you give your movie clips.

So for example if you are within a movieclip that you have given the instance name of "myMovieClip", your level will be...

_level0.myMovieClip

So to check this you would simply say:

if ( this == _level0.myMovieClip)
{
//do whatever it is you want to do
}

Now all that of course is presuming that you are in fact talking about levels and not depths! Whats the difference? Well, a level is the position of a movieclip in relation to _level0,

eg. _level0.myMovieClip.mySubMovieClip etc

Whereas a depth is the positioning of the movieclip on the stage - ie. whether it is above or below something. To get a depth you simply write:

this.getDepth();

and to test if a depth is a certain number you would say something like:

var myDepth:Number = this.getDepth();

if (myDepth == 1)
{
// do whatever
}

Finally, if it IS levels that you want and not depths, there is something else that you can check for - the name of the level. So rather than saying:

if (this == _level0.myMovieClip.mySubMovieClip)
{
// do whatever
}

(which can get very long winded if you are six levels down) you can alternatively say:

if (this._name == "mySubMovieClip")
{
// do whatever
}

which is much more efficient.

Hope that helps!!

2007-03-26 07:09:05 · answer #1 · answered by gromitski 5 · 0 0

this.valueOf() will evaluate to the path to current moveclip starting with "_levelX"

so you could do:
var level = parseInt( String(this).split('_level')[ 1 ] );

2007-03-26 01:44:27 · answer #2 · answered by Fabian 2 · 0 1

fedest.com, questions and answers