I was making a component that was using the native flash BlurFilter. It was essentially a tabbed pane, but would have a blur animation between panes that would move sideways. It was a simple effect, but looked pretty good in the end. However, I noticed a problem when I was using straight up MovieClips to create the blur than to use a BitmapData object to blur the pixels instead.
Since the component would load up content from linked MovieClips, everything in the pane was using the ‘attachMovie’ function. I noticed that after the initial content load (the panes themselves) were loaded, everything work smoothly, but the second I added more dynamic content within the panes after that, the blur would then stop working.
Apparently, this is a common theme for anything to do with AS2; do not use native components, classes, nothing. I guess the developers(or should I say, designers) were eating some bad granola at the time. Good thing there are still workarounds for these problems, even though they take a lot of time and even though the problem shouldn’t exist in the first place.
This particular solution was to create a BitmapData object containing the pixel data of all of panes before doing an animation and apply the blur to that and not the actual movies. This also increased processing speeds. Another solution would be to use an animation library like TweenLite or TweenMax.
I am actually very surprised at this library. Its easy to use and incredibly fast. Mad props goes to Jack Doyle for creating this software which is just a pleasure to read through. It’s well designed, developed and documentated; I couldn’t do a better job myself.
Anyone who’s every tried to create movieclips dynamically using the getNextHighestDepth function knows that when trying to delete that very same movie with removeMovieClip, it just simply does not work.
Senocular has a pretty nice explanation on how Zones of Depth work within flash, but it still doesn’t explain why the developer of this product decided it would be an awesome idea to not make it easy to delete.
Luckily, the fix for this is quite simple (compared to some of the other workarounds). When using getNextHighestDepth, it generally returns a depth of 1048575 or greater which is in the ‘reserve’ zones explained by the article above. Which means, if we are going to go be able to delete it, we need it to be within 0 to 1048575 depth.
We can accomplish this using the swapDepths function. Just need to swap the current movie’s depth to something that’s within normal range (and be sure that no movieclip is already present at said depth) and use the removeMovieClip function.
Example:
var mc1:MovieClip = this.createEmptyMovieClip('mc1', 10);
var mc2:MovieClip = this.createEmptyMovieClip('mc2', 1050000);
var mc3:MovieClip = this.createEmptyMovieClip('mc3', this.getNextHighestDepth());
mc1.removeMovieClip(); // Works.
mc2.removeMovieClip(); // Doesn't work, over 1048575
mc3.removeMovieClip(); // Same
mc2.swapDepths(999999);
mc2.removeMovieClip(); // Now it works
mc3.swapDepths(999998);
mc3.removeMovieClip(); // Same here
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.