PDA

View Full Version : Initialization: why does this happen?


notsofast
04-26-2002, 04:59 PM
I hope the answer to this isn't RTFM or RTFAQ. Why does this happen:

stop();
attachMovie("libMovieClip", "myMovie", 1);
trace(_root.myMovie);

outputs _level0.myMovie
but...

stop();
_root.myMovie = null;
attachMovie("libMovieClip", "myMovie", 1);
trace(_root.myMovie);

outputs null.

The movie still gets loaded, but I have no handle to it.

pinkaboo
04-26-2002, 06:43 PM
control - test Movie

then go to Debug - list variables and list objects

you should find that _level0.myMovie is listed as an object and "null" is listed as the variable _level.myMovie

is that what you mean/are after?

notsofast
04-26-2002, 07:09 PM
Thanks for pointing me to the debugger. That is helpful.

So it looks like attachMovie("mc", "myMovie", 1) creates some entity called _level0.myMovie, which is not really a variable, but can be used like one, sometimes. And when I create a variable with that same name beforehand, it covers up the thing that attachMovie() creates.

I'm seeing how it behaves now, but I still don't understand the underlying mechanism enough to be able to reason about it consistently. It strikes me as messy. Why can't attachMovie() just return a reference to the MC in a variable called myMovie?

Do I need to do some reading?