Inconsistency in relative pathing: FLVPlayback

Flash Add comments

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:

  1. to doctor every single path for all assets referenced
  2. use absolute pathing (start everything w/a slash)
  3. 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 );
       = 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.

  1. /index.htm loads /engine.swf
  2. engine.swf loads assets/player.swf
  3. 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.

6 responses to “Inconsistency in relative pathing: FLVPlayback”

  1. rapid4me Says:
    I don't usually reply on articles I read but I have to say this was just great. Keep up the good work.
  2. Jeff Kamerer Says:
    The behavior that you describe (FLVPlayback skin swfs loaded relative to the html and video loaded relative to the swf) is not an intentional behavior of the component but is simply the way that Flash Player handles things. You could arguably call it a design bug, and i think it is just a historical accident. Basically all swf files are always loaded relative to the html and not the swf, whether you are using AS1, AS2, AS3. However, when a NetStream is set up to load a video file, that load is done relative to the swf and NOT to the html. So any video component will have the same problem unless it somehow takes specific steps to work around the problem.
  3. Caelii Says:
    This is a rlelay intelligent way to answer the question.
  4. Deesnay Says:
    The approach 4 is: Place your html pages and Flash assets anywhere, but pass a variable from each html page to the Flash to let it know the right path to contents.
    Assign a default value to this variable, so that you can test when compiling, without requiring to test within the html page.
  5. kontur Says:
    So glad I came across this posting, as I was observing similar behavior and just couldn't make any sense of it. In the great wonderland of Flash obscurities this one is quite amongst the top of weird things.

    Also, I have come across this only after revisiting a project after quite a while, so it previously has worked as you'd expect (paths relative to embedding html), but now with a recompiled swf it does not work any longer as expected.

    Thanks for documenting your findings here!
  6. Sarah Says:
    All the previous soitulons didn't work for me.Here's what I did.I put this code in frame one of my file.My instance of FLVPlayback is called myVid so just replace myVid with the name that you gave your FLVPlayback instance.import;use namespace flvplayback_internal;myVid.uiMgr.dispatchMessage(UIManager.MUTE_ON_BUTTON);

Leave a Reply

Powered by Mango Blog. Design and Icons by N.Design Studio