开发者

How to get url path of self (movieclip) in flash within a hierarchy of multiple parent movieclips?

Let's say I am loading a movieclip from a remote url within another movieclip on another server.

This movieclip now needs to load another child movie clip on the same server as itself.

How can it get its own url and not the url of its parent container so as to load this child ? Because if it refers to "child.swf" it will be rela开发者_高级运维tive to the super parent container insted of the first server isn't it ? So it will not be able to load the child correctly if all it can get is the url of the parent.


In ActionScript 3, each clip has a LoaderInfo object that contains lots of info about the loaded object. In particular, there is a url property that gives you the URL of the loaded SWF itself. Also, the loaderURL property will give you the URL of the parent SWF. If necessary, you can even climb up the loader tree, using something like this:

var info:LoaderInfo = loaderInfo;
while(info.loader) { 
    trace(info.loaderURL);
    info = info.loader.loaderInfo;
}
// now info contains the topmost loaderInfo.

You'll probably want to do some string splicing to get the path without the filename, something like:

var url:String = loaderInfo.url;
url = url.substring(0, url.lastIndexOf("/")+1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜