CMXtraneous: Flash

Right on the edge of useful

Unexpected "Gotcha" with Relative Paths in ActionScript

Posted Friday, August 25, 2006 9:14:55 PM by David Stiller

David Stiller

I mentioned a fact-of-life “gotcha” on my personal dev blog not long ago, pertaining to relative paths in ActionScript.  In a nutshell, a SWF’s point of view changes depending on how it’s embedded.  A SWF considers relative paths from its own folder when played in a Projector.  That makes perfect sense.  On the other hand, a SWF embedded in an HTML document, as played by the Flash Player plug-in, sees things differently.  To a SWF in an HTML document, relative paths begin from the folder of the HTML document.

For example, if a root HTML document embeds a SWF in a flashcontent subfolder, and if that SWF loads a JPG from the same folder as itself, ActionScript must nonetheless include a reference to the flashcontent subfolder — because that’s where that JPG is located from the HTML’s point of view.  This can quickly confuse matters when you test the SWF from inside Flash, because the Flash IDE plays SWFs inside a special Projector (see (Perhaps) Unexpected Point of View:  SWF Defers to HTML for some workarounds).

That’s tricky enough as it is, but I just discovered an exception.

An HTML-embedded SWF considers relative paths from the folder of its HTML file unless … unless you’re loading an FLV (Flash video) file.  For some reason, FLV references — even in HTML-embedded SWFs — start from the SWF’s own point of view.  This is true of the FLVPlayback Component and also a plain vanilla Video object.

Category tags: Flash