flash.net

# URLVariables - AS3

Package | flash.net
Class | public dynamic class URLVariables
Inheritance | URLVariables Object

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4

The URLVariables class allows you to transfer variables between an application and a server. Use URLVariables objects with methods of the URLLoader class, with the `data` property of the URLRequest class, and with flash.net package functions.

View the examples

Learn more

Loading external data

Related API Elements

URLLoader

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | URLVariables(source:String = null) Creates a new URLVariables object. | URLVariables
|  | decode(source:String):void Converts the variable string to properties of the specified URLVariables object. | URLVariables
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns a string containing all enumerable variables, in the MIME content encoding application/x-www-form-urlencoded. | URLVariables
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Constructor Detail

### URLVariables

()
Constructor

`public function URLVariables(source:String = null)`

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4

Creates a new URLVariables object. You pass URLVariables objects to the `data` property of URLRequest objects.

If you call the URLVariables constructor with a string, the `decode()` method is automatically called to convert the string to properties of the URLVariables object.

Parameters

| `source:String` (default = `null`)`` — A URL-encoded string containing name/value pairs.

Method Detail

### decode

()
method

`public function decode(source:String):void`

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4

Converts the variable string to properties of the specified URLVariables object.

This method is used internally by the URLVariables events. Most users do not need to call this method directly.

Parameters

| `source:String` — A URL-encoded query string containing name/value pairs.

Throws

| `Error` — The source parameter must be a URL-encoded query string containing name/value pairs.

Learn more

Loading external data
Example ( How to use this example )
The following examples show how you can parse URL encoded strings. Example provided by ActionScriptExamples.com.
Copy

    // The first method passes the string to be decoded to the URLVariables class constructor:
    var urlVariables:URLVariables = new URLVariables("firstName=Tom&lastName=Jones");
    lbl.text = urlVariables.lastName + "," + urlVariables.firstName;

    // The second method uses the decode() method to parse the URL encoded string:
    var urlVariables:URLVariables = new URLVariables();
    urlVariables.decode("firstName=Tom&lastName=Jones");
    lbl.text = urlVariables.lastName + "," + urlVariables.firstName;

### toString

()
method

`public function toString():String`

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 1.0, Flash Player 9, Flash Lite 4

Returns a string containing all enumerable variables, in the MIME content encoding application/x-www-form-urlencoded.

Returns

| `String` — A URL-encoded string containing name/value pairs.

Examples How to use this example
URLVariablesExample.as
The following example opens the remote application hosted at http://www.[yourDomain].com/application.jsp in a new browser window and passes data about a user session, captured in a URLVariables object, to the application.

Highlights of the example follow:

1. The constructor function creates a URLRequest instance named `request`, taking the URL of the remote application as a parameter.
2. A URLVariables object is created and two of its properties are assigned values.
3. The URLVariables object is assigned to the `data` property of the URLRequest object.
4. The example calls `navigateToURL`, which opens a new browser window to the remote application's URL.

Note: To run the example, the remote application URL in the example must be replaced with a working URL. Additionally, you would need server code to process the information captured by Flash Player in the URLVariables object.

Copy

    package {
        import flash.display.Sprite;
        import flash.net.navigateToURL;
        import flash.net.URLRequest;
        import flash.net.URLVariables;

        public class URLVariablesExample extends Sprite {

            public function URLVariablesExample() {
                var url:String = "http://www.[yourDomain].com/application.jsp";
                var request:URLRequest = new URLRequest(url);
                var variables:URLVariables = new URLVariables();
                variables.exampleSessionId = new Date().getTime();
                variables.exampleUserLabel = "guest";
                request.data = variables;
                navigateToURL(request);
            }
        }
    }

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00