Flash CS4 Playing a Movie in a Movie in a Movie… Its all Relative!

fcs4[AS2, Flash CS4 Professional]

This might sound silly, but it is extremely useful. I just did a job for a client that needed to rotate their banners on a site that they had done for them 4 years ago. The site was hard coded to:


loadMovie(“flash/MovieB.swf”, intro_mc);

intro_mc is a simple, 1 frame movie in MovieA’s library that holds a Rectangle shape the size of the banner area. You use this rectangle to precisely position the asset in Movie A. intro_mc is placed as soon as it is needed, sometimes before the frame here that loads it.


This movie has the job of loading banners and displaying them. This is a great approach for lots of reasons, but for us the most important is that we don’t have to hard-code our banner rotation worker, MovieB, into MovieA or any other caller.

MovieB loads it’s movies from an XML file called banners.xml, which looks like this:


You notice anything interesting? bannerRepeat allows the user to determine how many times that banner should loop before proceeding to the next banner. Once at the bottom of this file, MovieB starts from the top, looping.

So hopefully now you can see why a 3-tiered model is ideal. All we need to do is call MovieB from anywhere, and it works! The file banners.xml lives in a folder beneath MovieB called simply /banners. I load each banner, stop it, and change the alpha to 0.

Here is a snippet of how I load the banners:

runningBannerName was needed because some banners don’t behave, and start themselves! I noticed that a non-desired banner would enter here while the desired was running. Some things you can’t forsee! playNextMovie() is called each time a playing movie has reached it’s end, and has no more loops to play (per banners.xml):

There is alot here, so I’ll just point out the main points, and answer any questions in Comments below. Seeing a few of the variables declared at the top to this frame (the only frame in the movie) might help:

As you can see, there are a few ways we need to track banners. One is by the 0-based index in banners.xml, the other is in the assigned name (banner1, banner2, …, bannerN), and the other is the full relative path to the banner itself (from banners.xml).

So now we come to the reason for the post. The above will not work. The client called and said that MovieB never loaded, and no banners were visible. I called MovieB again stand-alone, and it worked perfectly. What up?

The problem was one of target scope. With _level0 I was calling an ABSOLUTE target. When MovieB was loaded into MovieA, any absolute calls within MovieB will refer to MovieA‘s coordinates (or frame of reference).

That was it! But there is another gotcha here. Remember in the banners.xml file how we specified the relative path to the banners? Remember also that MovieB was in a sub-directory of MovieA called “flash” (see loadMovie() above)? Common sense would have told you the file structure would look like this:


But you’d be wrong! Because everything is relative, and MovieB‘s frame of reference is now MovieA‘s, the structure now looks like:

So you see, even though we load banners.xml from MovieB and it has relative paths, the actual place the relative paths are anchored is at MovieA‘s level!

So there you have it. You can see why a 3-toered design works so well, how to allow your users to change the banners, order and loops for each with a single XML file, and also how to lay out your file structure to accommodate the targets.

It’s all RELATIVE!

Leave a Reply

Your email address will not be published. Required fields are marked *