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.

Actionscript:
  1. /* example usage */
  2. var url:URL = new URL("http://secretuser:secretpass@example.com:80/foo/bar.php?var1=foo#abc");
  3. trace(  'scheme:'+url.scheme+'\n'
  4.         + 'host:'+url.host+'\n'
  5.         + 'port:'+url.port+'\n'
  6.         + 'path:'+url.path+'\n'
  7.         + 'fragment:'+url.fragment+'\n'
  8.         + '---\n'
  9.         + 'user:'+url.userinfo.user+'\n'
  10.         + 'pass:'+url.userinfo.pass+'\n'
  11.         + '---\n'
  12.         + 'query.raw:'+url.query.raw+'\n'
  13.         + 'query.parsed.var1:'+url.query.parsed.var1+'\n'
  14.         + 'query.parsed.var2:'+url.query.parsed.var2+'\n'
  15. );

Get it if you have some use for it: http://dev.dschini.org/as3/URL.as (before it gets lost in my archive)

7 Comments

  1. AS3 URL class « Ramblings 2008-07-5, 9:35 pm

    [...] 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. [...]

  2. John Bailey 2008-08-15, 5:16 pm

    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?

  3. Manfred Weber 2008-08-15, 5:38 pm

    Hey John,
    thanks for your feedback!
    Well, why not static? Because this was just hacked together quickly. Feel free to improve it! ;)
    Regards Manfred

  4. Flash Tutorials | AS3 Classes Roundup Part2 | Lemlinh.com 2008-08-25, 8:58 am

    [...] Read more [...]

  5. Leigh 2008-12-12, 2:29 pm

    In Flex3 you can ususally make do with the URLUtils class…

  6. Wes 2009-03-4, 9:23 pm

    Useful post!

    get fragment() failed on null, might need to add a check against null there.

    Mine: if(_fragment==null)return”";

  7. SteveO 2009-05-27, 11:19 am

    Great stuff. This was just what I was after thanks Manfred! Keep up the good work :o)

Add a Comment