Top Level

# TypeError - AS3

Package | Top Level
Class | public dynamic class TypeError
Inheritance | TypeError Error Object

Language Version: | ActionScript 3.0

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

A TypeError exception is thrown when the actual type of an operand is different from the expected type.

In addition, this exception is thrown when:

- An actual parameter to a function or method could not be coerced to the formal parameter type.
- A value is assigned to a variable and cannot be coerced to the variable's type.
- The right side of the `is` or `instanceof` operator is not a valid type.
- The `super` keyword is used illegally.
- A property lookup results in more than one binding, and is therefore ambiguous.
- A method is invoked on an incompatible object. For example, a TypeError exception is thrown if a RegExp class method is "grafted" onto a generic object and then invoked.

View the examples

More examples

Responding to error events and status

Related API Elements

is operator
instanceof operator
super statement
RegExp class

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
|  | errorID : int [read-only] Contains the reference number associated with the specific error message. | Error
|  | message : String Contains the message associated with the Error object. | Error
|  | name : String Contains the name of the Error object. | Error

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | TypeError(message:String = "") Creates a new TypeError object. | TypeError
|  | getStackTrace():String Returns the call stack for an error at the time of the error's construction as a string. | Error
|  | 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 [override] Returns the string "Error" by default or the value contained in the Error.message property, if defined. | Error
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Constructor Detail

### TypeError

()
Constructor

`public function TypeError(message:String = "")`

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

Creates a new TypeError object.

Parameters

| `message:String` (default = "``")`` — Contains the message associated with the TypeError object.

More examples

Responding to error events and status
Examples How to use this example
TypeErrorExample.as
The following example shows how a TypeError exception can be generated and handled within a `try..catch` statement.
Copy

    package {
        import flash.display.DisplayObject;
        import flash.display.Sprite;

        public class TypeErrorExample extends Sprite {
            public function TypeErrorExample() {
                try {
                    var child:Object = new Object();
                    addChild(DisplayObject(child));
                }
                catch(e:TypeError) {
                    trace(e);
                }
            }
        }
    }

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