Packagemx.utils
Classpublic class URLUtil
InheritanceURLUtil Inheritance Object

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

The URLUtil class is a static class with methods for working with full and relative URLs within Flex.

See also

mx.managers.BrowserManager


Public Methods
 MethodDefined By
  
getFullURL(rootURL:String, url:String):String
[static] Converts a potentially relative URL to a fully-qualified URL.
URLUtil
  
getPort(url:String):uint
[static] Returns the port number from the specified URL.
URLUtil
  
getProtocol(url:String):String
[static] Returns the protocol section of the specified URL.
URLUtil
  
getServerName(url:String):String
[static] Returns the server name from the specified URL.
URLUtil
  
getServerNameWithPort(url:String):String
[static] Returns the domain and port information from the specified URL.
URLUtil
  
hasTokens(url:String):Boolean
[static] Given a url, determines whether the url contains the server.name and server.port tokens.
URLUtil
  
[static] If the LoaderConfig.url property is not available, the replaceTokens() method will not replace the server name and port properties properly.
URLUtil
  
isHttpsURL(url:String):Boolean
[static] Determines if the URL uses the secure HTTPS protocol.
URLUtil
  
isHttpURL(url:String):Boolean
[static] Determines if the URL uses the HTTP, HTTPS, or RTMP protocol.
URLUtil
  
objectToString(object:Object, separator:String, encodeURL:Boolean):String
[static] Enumerates an object's dynamic properties (by using a for..in loop) and returns a String.
URLUtil
  
replacePort(uri:String, newPort:uint):String
[static] Returns a new String with the port replaced with the specified port.
URLUtil
  
replaceProtocol(uri:String, newProtocol:String):String
[static] Replaces the protocol of the specified URI with the given protocol.
URLUtil
  
replaceTokens(url:String):String
[static] Returns a new String with the port and server tokens replaced with the port and server from the currently running application.
URLUtil
  
stringToObject(string:String, separator:String, decodeURL:Boolean):Object
[static] Returns an object from a String.
URLUtil
  
urisEqual(uri1:String, uri2:String):Boolean
[static] Tests whether two URI Strings are equivalent, ignoring case and differences in trailing slashes.
URLUtil
Public Constants
 ConstantDefined By
  SERVER_NAME_TOKEN : String = {server.name}
[static] The pattern in the String that is passed to the replaceTokens() method that is replaced by the application's server name.
URLUtil
  SERVER_PORT_TOKEN : String = {server.port}
[static] The pattern in the String that is passed to the replaceTokens() method that is replaced by the application's port.
URLUtil
Method Detail
getFullURL()method
public static function getFullURL(rootURL:String, url:String):String

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Converts a potentially relative URL to a fully-qualified URL. If the URL is not relative, it is returned as is. If the URL starts with a slash, the host and port from the root URL are prepended. Otherwise, the host, port, and path are prepended.

Parameters

rootURL:String — URL used to resolve the URL specified by the url parameter, if url is relative.
 
url:String — URL to convert.

Returns
String — Fully-qualified URL.
getPort()method 
public static function getPort(url:String):uint

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Returns the port number from the specified URL.

Parameters

url:String — The URL to analyze.

Returns
uint — The port number of the specified URL.
getProtocol()method 
public static function getProtocol(url:String):String

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Returns the protocol section of the specified URL. The following examples show what is returned based on different URLs:

          getProtocol("https://localhost:2700/") returns "https"
          getProtocol("rtmp://www.myCompany.com/myMainDirectory/groupChatApp/HelpDesk") returns "rtmp"
          getProtocol("rtmpt:/sharedWhiteboardApp/June2002") returns "rtmpt"
          getProtocol("rtmp::1234/chatApp/room_name") returns "rtmp"
          

Parameters

url:String — String containing the URL to parse.

Returns
String — The protocol or an empty String if no protocol is specified.
getServerName()method 
public static function getServerName(url:String):String

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Returns the server name from the specified URL.

Parameters

url:String — The URL to analyze.

Returns
String — The server name of the specified URL.
getServerNameWithPort()method 
public static function getServerNameWithPort(url:String):String

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Returns the domain and port information from the specified URL.

Parameters

url:String — The URL to analyze.

Returns
String — The server name and port of the specified URL.
hasTokens()method 
public static function hasTokens(url:String):Boolean

Language Version : ActionScript 3.0
Product Version : Flex 4
Runtime Versions : Flash Player 10, AIR 1.5

Given a url, determines whether the url contains the server.name and server.port tokens.

Parameters

url:String — A url string.

Returns
Boolean — true if the url contains server.name and server.port tokens.
hasUnresolvableTokens()method 
public static function hasUnresolvableTokens():Boolean

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

If the LoaderConfig.url property is not available, the replaceTokens() method will not replace the server name and port properties properly.

Returns
Boolean — true if the LoaderConfig.url property is not available. Otherwise, false.
isHttpsURL()method 
public static function isHttpsURL(url:String):Boolean

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Determines if the URL uses the secure HTTPS protocol.

Parameters

url:String — The URL to analyze.

Returns
Boolean — true if the URL starts with "https://".
isHttpURL()method 
public static function isHttpURL(url:String):Boolean

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Determines if the URL uses the HTTP, HTTPS, or RTMP protocol.

Parameters

url:String — The URL to analyze.

Returns
Boolean — true if the URL starts with "http://", "https://", or "rtmp://".
objectToString()method 
public static function objectToString(object:Object, separator:String, encodeURL:Boolean):String

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Enumerates an object's dynamic properties (by using a for..in loop) and returns a String. You typically use this method to convert an ActionScript object to a String that you then append to the end of a URL. By default, invalid URL characters are URL-encoded (converted to the %XX format).

For example:

          var o:Object = { name: "Alex", age: 21 };
          var s:String = URLUtil.objectToString(o,";",true);
          trace(s);
          
Prints "name=Alex;age=21" to the trace log.

Parameters

object:Object — The object to convert to a String.
 
separator:String — The character that separates each of the object's property:value pair in the String.
 
encodeURL:Boolean — Whether or not to URL-encode the String.

Returns
String — The object that was passed to the method.
replacePort()method 
public static function replacePort(uri:String, newPort:uint):String

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Returns a new String with the port replaced with the specified port. If there is no port in the specified URI, the port is inserted. This method expects that a protocol has been specified within the URI.

Parameters

uri:String — String containing the URI in which the port is replaced.
 
newPort:uint — uint containing the new port to subsitute.

Returns
String — The URI with the new port.
replaceProtocol()method 
public static function replaceProtocol(uri:String, newProtocol:String):String

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Replaces the protocol of the specified URI with the given protocol.

Parameters

uri:String — String containing the URI in which the protocol needs to be replaced.
 
newProtocol:String — String containing the new protocol to use.

Returns
String — The URI with the protocol replaced, or an empty String if the URI does not contain a protocol.
replaceTokens()method 
public static function replaceTokens(url:String):String

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Returns a new String with the port and server tokens replaced with the port and server from the currently running application.

Parameters

url:String — String containing the SERVER_NAME_TOKEN and/or SERVER_NAME_PORT which should be replaced by the port and server from the application.

Returns
String — The URI with the port and server replaced.
stringToObject()method 
public static function stringToObject(string:String, separator:String, decodeURL:Boolean):Object

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Returns an object from a String. The String contains name=value pairs, which become dynamic properties of the returned object. These property pairs are separated by the specified separator. This method converts Numbers and Booleans, Arrays (defined by "[]"), and sub-objects (defined by "{}"). By default, URL patterns of the format %XX are converted to the appropriate String character.

For example:

          var s:String = "name=Alex;age=21";
          var o:Object = URLUtil.stringToObject(s, ";", true);
          
Returns the object: { name: "Alex", age: 21 }.

Parameters

string:String — The String to convert to an object.
 
separator:String — The character that separates name=value pairs in the String.
 
decodeURL:Boolean — Whether or not to decode URL-encoded characters in the String.

Returns
Object — The object containing properties and values extracted from the String passed to this method.
urisEqual()method 
public static function urisEqual(uri1:String, uri2:String):Boolean

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

Tests whether two URI Strings are equivalent, ignoring case and differences in trailing slashes.

Parameters

uri1:String — The first URI to compare.
 
uri2:String — The second URI to compare.

Returns
Boolean — true if the URIs are equal. Otherwise, false.
Constant Detail
SERVER_NAME_TOKENConstant
public static const SERVER_NAME_TOKEN:String = {server.name}

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

The pattern in the String that is passed to the replaceTokens() method that is replaced by the application's server name.

SERVER_PORT_TOKENConstant 
public static const SERVER_PORT_TOKEN:String = {server.port}

Language Version : ActionScript 3.0
Product Version : Flex 3
Runtime Versions : Flash Player 9, AIR 1.1

The pattern in the String that is passed to the replaceTokens() method that is replaced by the application's port.