问题
My file structure is this:
main.swf
/swf/child.swf
/video/testvideo.flv
When I compile the child.swf by itself, it loads and plays video just fine (using netStream.play(../video/testvideo.flv).
However, when I compile the main.swf, which at some point loads child.swf, I get this error when trying to play the video:
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
How am I supposed to configure the path so that it can be seen when I compile the main swf? I've tried changing the path to just video/testvideo.flv, and I still get the same error.
回答1:
The problem is that relative path is based on the parent movie clip, so when you test child.swf, the start path is /swf/ and when you test main.swf, the start path is /. If you want the video to play for both, you will need to do a little test. Something like this:
var rootPath:String = (root==this) ? "../" : "./";
netStream.play(rootPath + "video/testvideo.flv");
That way if you're testing child.swf, root == this
, so it will use ../video/testvideo.flv
as the path. If you're testing main.swf, root != this
, so it will use ./video/testvideo.flv
as the path.
来源:https://stackoverflow.com/questions/1358728/as3-playing-video-within-a-loaded-swf