For years, I have been frustrated by Flash's inability to load files relative to a the swf doing the loading; instead, the referenced files have always been relative to the html file that is instantiating the swf object. This always means you have take one of three approaches:
- to doctor every single path for all assets referenced
- use absolute pathing (start everything w/a slash)
- place your html file and swf file into the same directory
Number 1 is ideal, but definitely the most complex, particularly when you have swfs loading swf, loading swf, etc.
For our uses, number 2 is out, b/c echoEleven authors SCORM courses, which will be deployed ususally into a subdirectory. No LMS vendor will allow you to start unzipping courses into the root of thier LMS, nor should they.
So we settled on approach 3, albiet with some level of resentment.
Then came the AS 3.0 FLVPlayback component. This guy behaves differently.
When in the Flash authoring environment, it loads the skin and the flv source relative to the .swf file. This is as expected.
However, when in an html page, it loads the skin relative the htm file, but the flv relative to the .swf file. Kudos to David Stiller for pointing this out.
Consider the following code in assets/player.swf:
var videoSkin:String = "assets/videoSkin.swf";
//we are loading a flv
var player:FLVPlayback = new FLVPlayback();
player.source = assets/video.flv;
player.autoPlay = false;
addChild( player );
player.skin = videoSkin;
When running out of an html page, in the root, the request will be made for the following files:
- assets/player.swf
- assets/videoSkin.swf
- assets/assets/video.flv
The waters get muddier when the loading swf file is loaded by yet another swf in another directory. Consider the same example above, but add a engine.swf at the root level.
- /index.htm loads /engine.swf
- engine.swf loads assets/player.swf
- player.swf loads the FLV assets as before (assets/videoSkin.swf, assets/video.flv).
Now we see requests for the following files:
- index.htm
- engine.swf
- assets/player.swf
- assets/videoSkin.swf
- assets/video.flv
The video.flv is now relative to engine.swf.
So--is this by design or is it a bug? Well, it's probably in the component, so it is not a Flash Player bug. But I would argue that it is a component bug, just because it behaves differently than anything else in the Flash ecosystem.
Feb 17, 2010 at 7:36 AM I don't usually reply on articles I read but I have to say this was just great. Keep up the good work.