flash.net.dns

# DNSResolver - AS3

Package | flash.net.dns
Class | public class DNSResolver
Inheritance | DNSResolver EventDispatcher Object

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 2

The DNSResolver class lets you lookup Domain Name System (DNS) resource records.

AIR profile support: This feature is supported on all desktop operating systems, but is not supported on mobile devices. It is partially supported on AIR for TV devices. You can test for support at run time using the `DNSResolver.isSupported` property. See AIR Profile Support for more information regarding API support across multiple profiles.

You can look up the following types of resource records:

- ARecord: IPv4 address for a host.
- AAAARecord: IPv6 address for a host.
- MXRecord: mail exchange record for a host.
- PTRRecord: host name for an IP address.
- SRVRecord: service record for a service

The following table indicates DNS lookup support on AIR for TV devices. Unsupported requests result in the DNSResolver object dispatching an flash.events.ErrorEvent object.

Record type specified in `DNSResolver.lookup()` | Support
--- | ---
ARecord | Full support
AAAARecord | Full support
MXRecord | Not supported
PTRRecord | Supported only for IPv4 addresses, not for IPv6 addresses
SRVRecord | Not supported

View the examples

More examples

Domain Name System (DNS) records

Related API Elements

ARecord
AAAARecord
MXRecord
PTRRecord
SRVRecord

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
|  | isSupported : Boolean [static] [read-only] Indicates whether DNS lookups are supported on the client system. | DNSResolver

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | DNSResolver() Creates a DNSResolver object. | DNSResolver
|  | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. | EventDispatcher
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | EventDispatcher
|  | hasEventListener(type:String):Boolean Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | EventDispatcher
|  | 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
|  | lookup(host:String, recordType:Class):void Looks up a DNS resource record based on a query string. | DNSResolver
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void Removes a listener from the EventDispatcher object. | EventDispatcher
|  | 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 the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | willTrigger(type:String):Boolean Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | EventDispatcher

Events
Click for more information on events
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | activate | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher
|  | deactivate | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher
|  | error | Dispatched when an error occurred during a DNS lookup. | DNSResolver
|  | lookup | Dispatched when a DNS look-up is complete. | DNSResolver

Property Detail

### isSupported

property

`isSupported:Boolean` [read-only]

Runtime Versions: | AIR 2

Indicates whether DNS lookups are supported on the client system.

Implementation
`public static function get isSupported():Boolean`
Constructor Detail

### DNSResolver

()
Constructor

`public function DNSResolver()`

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 2

Creates a DNSResolver object.

Method Detail

### lookup

()
method

`public function lookup(host:String, recordType:Class):void`

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 2

Looks up a DNS resource record based on a query string.

The `lookup()` method performs a DNS lookup asynchronously. Listen for the lookup event to get the results of the lookup. Listen for the error event to receive errors. Results are dispatched in a DNSResolverEvent object.

To specify the type of resource record to look up, pass the corresponding class in the `recordType` parameter. (Pass the class name itself and not a string containing the class name.)

The content of the query string passed to the method depends on the type of resource record being looked up. The following list illustrates the query string to use for each record type.

Record type | Query string | Example
--- | --- | ---
ARecord | host name | "example.com"
AAAARecord | host name | "example.com"
MXRecord | host name | "example.com"
PTRRecord | IP address | "208.77.188.166"
SRVRecord | _service._protocol.host. | "_sip._tcp.example.com."

Parameters

| `host:String` — the query string, such as a host name, IP address, or service locator.
| `recordType:Class` — The class representing the type of DNS resource record to look up.

Events

| `lookup:`DNSResolverEvent`` — dispatched when the lookup is completed successfully.
| `error:`ErrorEvent`` — dispatched when the lookup fails (including when no records exist).

Throws

| `ArgumentError` — The `host` parameter value is not an appropriate query string or the `recordType` class is not recognized.

Related API Elements

DNSResolverEvent
Event Detail

### error

Event

Event Object Type: `flash.events.ErrorEvent`
property ErrorEvent.type = `flash.events.ErrorEvent.ERROR`

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 2

Dispatched when an error occurred during a DNS lookup.

Defines the value of the `type` property of an `error` event object.

This event has the following properties:

Property | Value
--- | ---
`bubbles` | `false`
`cancelable` | `false`; there is no default behavior to cancel.
`currentTarget` | The object that is actively processing the Event object with an event listener.
`target` | The object experiencing a network operation failure.
`text` | Text to be displayed as an error message.

### lookup

Event

Event Object Type: `flash.events.DNSResolverEvent`
property DNSResolverEvent.type = `flash.events.DNSResolverEvent.LOOKUP`

Language Version: | ActionScript 3.0

Runtime Versions: | AIR 2

Dispatched when a DNS look-up is complete.

Defines the value of the `type` property of a `lookup` event object.
Examples How to use this example
DNSResolverExample.as
The following example shows how to look up the supported types of DNS records:
Copy

    package
    {
        import flash.desktop.NativeApplication;
        import flash.display.Sprite;
        import flash.events.DNSResolverEvent;
        import flash.events.ErrorEvent;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.net.dns.AAAARecord;
        import flash.net.dns.ARecord;
        import flash.net.dns.DNSResolver;
        import flash.net.dns.MXRecord;
        import flash.net.dns.PTRRecord;
        import flash.net.dns.SRVRecord;
        import flash.utils.getQualifiedClassName;

        public class DNSResolverExample extends Sprite
        {
            private var resolver:DNSResolver = new DNSResolver();

            public function DNSResolverExample()
            {
                resolver.addEventListener( DNSResolverEvent.LOOKUP, lookupComplete );
                resolver.addEventListener( ErrorEvent.ERROR, lookupError );

                //Look up records
                resolver.lookup( "www.example.com", ARecord );
                resolver.lookup( "example.com", AAAARecord );
                resolver.lookup( "example.com", MXRecord );
                resolver.lookup( "208.77.188.166", PTRRecord );
                resolver.lookup( "127.0.0.1", PTRRecord );
                resolver.lookup( "2001:1890:110b:1e19:f06b:72db:7026:3d7a", PTRRecord );
                resolver.lookup( "_sip._tcp.example.com.", SRVRecord );
                resolver.lookup( "www.example.com", ARecord );

                this.stage.nativeWindow.activate();
            }

            private function lookupComplete( event:DNSResolverEvent ):void
            {
                trace( "Query string: " + event.host );
                trace( "Record type: " +  flash.utils.getQualifiedClassName( event.resourceRecords[0] ) +
                    ", count: " + event.resourceRecords.length );
                for each( var record in event.resourceRecords )
                {
                    if( record is ARecord ) trace( record.name + " : " + record.address );
                    if( record is AAAARecord ) trace( record.name + " : " + record.address );
                    if( record is MXRecord ) trace( record.name + " : " + record.exchange + ", " + record.preference );
                    if( record is PTRRecord ) trace( record.name + " : " + record.ptrdName );
                    if( record is SRVRecord ) trace( record.name + " : " + record.target + ", " + record.port +
                        ", " + record.priority + ", " + record.weight );
                }
            }

            private function lookupError( error:ErrorEvent ):void
            {
                trace("Error: " + error.text );
            }
        }
    }

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