Problems in Flash #01: Unique MovieClip Names

POSTED IN Actionscript, Flash Platform | TAGS : , , , June 26, 2008

This one has gotten me on several occasions without noticing. It’s quite annoying because it’s a hard one to spot.

Whenever you attach a MovieClip using attachMovie, they ask for the new name of the instance. Flash let’s you create MovieClips with the same name. This concerns me.

For one, it isn’t very good OOP to be able to have 2 objects of the same name, especially when you’re trying to access one and not the other (which is impossible using dot notation unless you stored a pointer to the MovieClip instance in a variable somewhere or remembered the depth of the MovieClip). On top of that, the MX components do not work properly if it’s in a MovieClip that has another one of the same name. I don’t know exactly why, but if they are not to work, why even let Flash be able to create 2 movies of the same name? Shouldn’t it be restricted? Maybe create some sort of runtime error/warning?

I never figured out what the programmers were thinking/smoking when they decided that letting people be able to create movies of same name. It has no purpose in programming(that I can think of), and I doubt it does for the design aspect as well.

I know that some people are thinking “But the ‘depth’ of the MovieClip is the real unique identifier!”.  Yes, I agree that every movie needs to be on a separate depth and if you create a MovieClip on said depth, it’s going to replace it.  Seems logical enough.  However, if you are to create many movies (like say, a particle generator), there is no way to remember or use all those depths unless you save them each in it’s own variable/array/object which is just ludicrous.

2 COMMENTS

  1. Paul says:

    You have an excellent point, but this is only relevant for Actionscript 2.0. Actionscript 3.0 has resolved these issues and is much more like a “real” programming language than a scripting language. Try it out.

  2. Yes, I do know this, but as it was pointed out in a previous post, this is all about AS2 since I’ve been working with it for enterprise/commercial projects. I also have 6 years experience with AS2 compared to 1 year of AS3. Thanks for the input.

Loading