/ Published in: ActionScript 3
Works great for parsing links in XML documents and arrays.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Use an XML object or an Array. This array is just an example var _arrLinks:Array = ["testfiletype.txt", "http://www.domain.com/", "something.fdz", "another-file.rtf", "www.somedomain.com", "domain.com"]; var _fileExt:String; var _strTmp:String; for (var i:uint = 0; i < _arrLinks.length; i++) { _strTmp = _arrLinks[i]; _fileExt = _strTmp.substr(0, 4); if (_fileExt == "www.") _fileExt = "www"; else if (_fileExt != "http") _fileExt = _strTmp.substr(_strTmp.lastIndexOf('.') + 1, _strTmp.length); switch (_fileExt) { case "swf": trace("This is a SWF file: " + _strTmp); break; case "txt": trace("This is a TXT file: " + _strTmp); break; case "http": trace("This is an HTTP link: " + _strTmp); break; case "www": trace("This is a WWW link, convert to an HTTP link: http://" + _strTmp); break; case "com": trace("This is a dot com link, convert to an HTTP link: http://" + _strTmp); break; default: trace("Unrecognized link or file extension. Please add (" + _fileExt + ") to the switch statment or change your filename."); break; } }