
Page 3 of 4
5. onKeyUp, onKeyDown and listeners
Naively using Movieclip.onKeyUp and Movieclip.onKeyDown will not work. This is because by default movieclips are not listeners of Key events. For example:
function showTimer()
{
trace(getTimer());
}
_root.onKeyDown = showTimer;
You can test your movie and press all the keys you want, you will never get the timer in the output window. Isn't Movieclip.onKeyDown exactly the same as onClipEvent(keyDown) ? Nope. To get the same functionality as with onClipEvent, you will need to add a listener, such as this:
function showTimer()
{
trace(getTimer());
}
Key.addListener(_root)
_root.onKeyDown = showTimer;
I believe this has to do with focus handling in components. See this article by Guy Watson of Flashguru fame for more info on listeners.
6. Movieclip.onLoad issues
In the same vein as the previous error, Movieclip.onLoad and onClipEvent(load) are NOT the same. The documentation tells all:
"This handler [Movieclip.onLoad] can be used only with movie clips for which you have a symbol in the library that is associated with a class."
So Movieclip.onLoad is nothing like onClipEvent(load). Unless you know what you're doing, don't use it. Look at the the MovieClipLoader class for an onLoad handler that actually works, or check out the Loader component.
7. LoadMovie and LoadMovieNum
I've had terrible difficulty with this when learning Actionscript way back when Flash 4 was the thing. LoadMovieNum loads movies into what is called a level. In each level there are depths. Levels have precedence over depths, that is, any depth in level 1 is higher than any other depth in layer 1. Levels can be accessed cross-movie using _level0 or _level1, for example. Each level has its own _root. A level is not like a movie clip; you can't for example write _level1._visible = false and expect your movie to disappear.
MovieClip.LoadMovie loads a movie into a movieclip. The loaded movie then 'becomes' a movieclip in its own right. You may for example use:
_root.createEmptyMovieClip('empty', 0);
empty.loadMovie('example.swf');
empty._x = 100;
empty._y = 200;
The contents of example.swf will be placed in the empty movieclip. When it appears, it will be placed on (100, 200). As the loaded movie 'becomes' the movieclip, it does not have its own _root.
Generally speaking, I suggest that you do NOT use loadMovieNum unless you have a very specific reason to do so. Mainly, the only (valid) reason I find is that you need to load in a movie that is designed to be used alone (needs its own _root) which you do not have the source for. LoadMovieNum is just not flexible. Your movie will be at (0,0) sitting there and that's it. Now this admittedly radical opinion will displease some; you are free not to follow my advice on this.
In any event if you are to load a movie (especially someone else's) into a movieclip it probably won't work immediately. The reason is that the loaded movie refers to _root, which is not the same when the movie is played alone or loaded in a movieclip. This is where most beginners abandon. You shouldn't.
You need to convert absolute references to relative references in which _root does not appear. So all of these _root's will be replaced with _parent and this. Not a simple matter in most cases, but you will learn a great deal. First load the source into Flash and make it work alone without all of the _root's. Then try it again as a loaded movie clip and it should work fine.
8. Files don't work online
Please, before anything else, when files don't work online, first check if all the support files are correctly uploaded. I once had a problem on a test server where all of the XML files became empty once on the server; probably some filter on the server.
Place your HTML file and your SWF in the SAME folder, OR use absolute URLS. Of course, update the HTML file to match the situation. When Flash encounters a load command that uses a relative URL it passes it along to the browser. The browser must decide whether that URL is relative to the Flash file or to the HTML file. If they are in the same folder, there is no ambiguity. However, if that is not the case, do you know what it will choose? I don't either! Save yourself the trouble, keep the main swf in the same folder as the HTML.When files are loaded through one of Flash's numerous load functions (loadMovie, MovieClipLoader.loadClip, XML.load, Sound.loadSound, etc.), there is always a lag between the load call and the data being received. You must take that into account. Never play with a movie you're not 100% sure is loaded. Using MovieClipLoader and LoadVars is safer than loadMovie and loadVariables because of all the neat loading events they fire.
Double-check if your preloaders are working. If you don't have them, use them! Check out the progress bar component, it can hook to most loading functions and objects, so you'll have visual feedback.
9. Preloader in first frame does not appear immediately
This goes with the previous error, but I've seen this so often it deserves its own point. You create a preloader of some kind and it takes a good deal of time to show up, even though it's on the first frame and only a few kbs. What's going on?
The reason is that Flash may place objects before the first frame. Your preloader will only be shown once these are loaded. The three usual suspects are: movieclips, components and sounds. When you check Export for Actionscript in the Linkage properties of a movieclip, by default the "Export in first frame" option is selected. Uncheck it and see if your preloader does the same thing. You needn't put your file online to see if it works; simply press Ctrl+Enter twice to do a streaming simulation.

After taking the time to uncheck the 'Export in First Frame' option in the movieclip that was causing the problem, you may find your attachmovie calls cease to function properly. This is because the clip is not exported in the swf anymore. Place an instance of the movieclip on frame 2 of your movie off of the stage. It need only to be shown on a single frame, so you can put a blank keyframe on the movieclip's layer in frame 3.
The second culprit: components. Like movieclips, components have linkage properties. If you uncheck export in first frame on a standard v2 component, you'll notice you will still have the same loading issues. That's because the component's class is still loaded before the first frame. What you have to do is go into File > Publish settings; in the Flash tab, click the Settings button to the right of the "Actionscript Version" option; in "Export frame for classes", write 2instead of 1. That should do the trick.
The third element that will cause preloading issues is sounds. Sounds that are exported for actionscript, like movieclips and components, are exported by default before anything on the first frame. As usual, uncheck "Export in first frame" in the Linkage properties dialog. You must include the sound somewhere in your movie or it won't be exported. If you place it naively on the second frame, the sound will play: this is bad. What I suggest rather is this procedure: create an empty movie clip. In the first frame, place a stop() action. In the second frame, create an empty keyframe. In the properties panel, select the sound you need to preload from the Sound combo box. Place an instance of this movieclip in the the second frame of your movie. This way, Flash sees an instance of the sound, so it will preload it in the second frame, but the movieclip will never reach the sound, thanks to the stop action in the first frame.
