Ever aiming for a small SWF footprint, I often load external assets at runtime. This includes FLVs, MP3s, XML, sometimes CSS, and frequently images (which even includes PNG — woo hoo! — since the release of Flash Player 8). As often as not, I use a relative path to specify the location of an asset. This means the resolution of that path depends on its position in relation to the SWF itself. For example, with something like mc.loadMovie("external.jpg");, it only makes sense that the SWF with this ActionScript must reside in the same folder as the JPG it loads. Why? Because no absolute path to the JPG is provided — how would the SWF possibly know where else to look, other than its own folder?
If the SWF was in one folder and the JPG in another, you’d have to provide a path to that location. For example, if the SWF was inside a folder named swf and the JPG was inside a subfolder of the first — say, swf/images — you would have to specify mc.loadMovie("images/external.jpg");. The SWF would interpret that as, “Okay, start from where I am; now, look for a folder named ‘images,’ then look for external.jpg.” If the images folder was side-by-side with the swf folder, the relative path would instead be mc.loadMovie("../images/external.jpg");; that is, “Ah, back up one folder [that’s what the .. means], then look for a folder named ‘images,” then look for external.jpg.” All of this should be pretty straightforward, and it always works when the HTML document is also in the same folder as the SWF. But there’s the rub: what happens if it isn’t? Keep reading »