2008-05-12
AS3 - URL Class
I could not find it in the net so I hacked something together quickly. A simple URL class that parses an url string.
-
/* example usage */
-
var url:URL = new URL("http://secretuser:secretpass@example.com:80/foo/bar.php?var1=foo#abc");
-
trace( 'scheme:'+url.scheme+'\n'
-
+ 'host:'+url.host+'\n'
-
+ 'port:'+url.port+'\n'
-
+ 'path:'+url.path+'\n'
-
+ 'fragment:'+url.fragment+'\n'
-
+ '---\n'
-
+ 'user:'+url.userinfo.user+'\n'
-
+ 'pass:'+url.userinfo.pass+'\n'
-
+ '---\n'
-
+ 'query.raw:'+url.query.raw+'\n'
-
+ 'query.parsed.var1:'+url.query.parsed.var1+'\n'
-
+ 'query.parsed.var2:'+url.query.parsed.var2+'\n'
-
);
Get it if you have some use for it: http://dev.dschini.org/as3/URL.as (before it gets lost in my archive)
3 Comments
-
[...] AS3 - URL Class | Manfred Weber`s Weblog I could not find it in the net so I hacked something together quickly. A simple URL class that parses an url string. [...]
-
Wonderful! The exact results I was looking for and more. The script is clean with good commenting for the most part. You deserve mad props for this - yes, it’s simple but it’s done well.
One thing though, why not do public static? In that way you wouldn’t have to instantiate it and just do URL.host(”http://manfred.dschini.org/2008/05/12/as3-url-class/”), which would return manfred.dschini.org. What was your reasoning?
-
Hey John,
thanks for your feedback!
Well, why not static? Because this was just hacked together quickly. Feel free to improve it! ;)
Regards Manfred

