Resolving URLs: AS3 Bug?



A common task I've often run into is resolving URLs. Given a base URL and a relative URL, how do you obtain the resultant absolute URL? I've written routines that do this sort of thing in AS2, but AS3 makes it much easier on you. You can simply do this:




var AbsoluteURL = URLUtil.getFullURL(BaseURL, RelativeURL);


This is great-but it seems to fail resolving local URLs. Often when testing your application, you'll be working with files locally. When your base URL starts with "file:///" and you try to resolve it against a relative file name, getFullURL only returns the relative file name, not the entire URL.

So if your function call is:


var AbsoluteURL = URLUtil.getFullURL("file:///c:/Windows/", "data.xml");


you receive back "data.xml" instead of "file:///c:/Windows/data.xml". Has anyone else seen this behavior?

1 comment :

Anonymous said...

Yes, I see it in the opposite way - it treats a file: URL in the second parameter as if it were a relative URL, and just concatenates it to the first parameter at the 'lowest directory' junction.