PackageTop Level
Classpublic dynamic class Object
Subclasses Accessibility, AccessibilityProperties, ActionScriptVersion, AntiAliasType, ApplicationDomain, arguments, Array, BitmapData, BitmapDataChannel, BitmapFilter, BitmapFilterQuality, BitmapFilterType, BlendMode, Boolean, BreakOpportunity, ByteArray, Capabilities, CapsStyle, Class, Clipboard, ClipboardFormats, ClipboardTransferMode, ColorTransform, ContentElement, ContextMenuBuiltInItems, ContextMenuClipboardItems, CSMSettings, CustomActions, Date, Dictionary, DigitCase, DigitWidth, DisplacementMapFilterMode, ElementFormat, Endian, Error, Event, EventDispatcher, EventPhase, ExternalInterface, FileFilter, Fill, Font, FontDescription, FontLookup, FontMetrics, FontPosture, FontStyle, FontType, FontWeight, FrameLabel, Function, GlyphRotation, GradientType, Graphics, GraphicsBitmapFill, GraphicsEndFill, GraphicsGradientFill, GraphicsPath, GraphicsPathCommand, GraphicsPathWinding, GraphicsShaderFill, GraphicsSolidFill, GraphicsStroke, GraphicsTrianglePath, GridFitType, ID3Info, IMEConversionMode, int, InterpolationMethod, JointStyle, JustificationStyle, Kerning, Keyboard, KeyLocation, LigatureLevel, LineJustification, LineScaleMode, LoaderContext, Math, Matrix, Matrix3D, Mouse, MouseCursor, Namespace, NetStreamInfo, NetStreamPlayTransitions, Number, ObjectEncoding, Orientation3D, PerspectiveProjection, PixelSnapping, Point, PrintJobOptions, PrintJobOrientation, Proxy, QName, Rectangle, RegExp, Responder, Sample, Scene, Security, SecurityDomain, SecurityPanel, Shader, ShaderData, ShaderInput, ShaderParameter, ShaderParameterType, ShaderPrecision, SharedObjectFlushStatus, SoundCodec, SoundLoaderContext, SoundMixer, SoundTransform, SpreadMethod, StackFrame, StageAlign, StageDisplayState, StageQuality, StageScaleMode, String, SWFVersion, System, TabAlignment, TabStop, TextBaseline, TextBlock, TextColorType, TextDisplayMode, TextFieldAutoSize, TextFieldType, TextFormat, TextFormatAlign, TextJustifier, TextLineCreationResult, TextLineMetrics, TextLineMirrorRegion, TextLineValidity, TextRenderer, TextRotation, TextSnapshot, Transform, TriangleCulling, TypographicCase, uint, URLLoaderDataFormat, URLRequest, URLRequestHeader, URLRequestMethod, URLVariables, Utils3D, Vector, Vector3D, XML, XMLList, XMLNode, XMLNodeType, XMLUI

Player Version : Flash Player 9

The Object class is at the root of the ActionScript class hierarchy. Objects are created by constructors using the new operator syntax, and can have properties assigned to them dynamically. Objects can also be created by assigning an object literal, as in:
var obj:Object = {a:"foo", b:"bar"}

All classes that don't declare an explicit base class extend the built-in Object class.

You can use the Object class to create associative arrays. At its core, an associative array is an instance of the Object class, and each key-value pair is represented by a property and its value. Another reason to declare an associative array using the Object data type is that you can then use an object literal to populate your associative array (but only at the time you declare it). The following example creates an associative array using an object literal, accesses items using both the dot operator and the array access operator, and then adds a new key-value pair by creating a new property:

 var myAssocArray:Object = {fname:"John", lname:"Public"};
 trace(myAssocArray.fname);     // John
 trace(myAssocArray["lname"]);  // Public
 myAssocArray.initial = "Q";
 trace(myAssocArray.initial);   // Q

ActionScript 3.0 has two types of inheritance: class inheritance and prototype inheritance:

Both class inheritance and prototype inheritance can exist simultaneously, as shown in the following example:

 class A {
     var x = 1
     prototype.px = 2
 }
 dynamic class B extends A {
     var y = 3
     prototype.py = 4
 }
  
 var b = new B()
 b.x // 1 via class inheritance
 b.px // 2 via prototype inheritance from A.prototype
 b.y // 3
 b.py // 4 via prototype inheritance from B.prototype
  
 B.prototype.px = 5
 b.px // now 5 because B.prototype hides A.prototype
  
 b.px = 6
 b.px // now 6 because b hides B.prototype

Using functions instead of classes, you can construct custom prototype inheritance trees. With classes, the prototype inheritance tree mirrors the class inheritance tree. However, since the prototype objects are dynamic, you can add and delete prototype-based properties at run time.

View the examples

See also

prototype
Data type descriptions


Public Properties
 PropertyDefined By
  constructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  prototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined By
  
Creates an Object object and stores a reference to the object's constructor method in the object's constructor property.
Object
  
Indicates whether an object has a specified property defined.
Object
  
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
  
Indicates whether the specified property exists and is enumerable.
Object
  
Sets the availability of a dynamic property for loop operations.
Object
  
Returns the string representation of the specified object.
Object
  
Returns the primitive value of the specified object.
Object
Property Detail
constructorproperty
public var constructor:Object

Player Version : Flash Player 9

A reference to the class object or constructor function for a given object instance. If an object is an instance of a class, the constructor property holds a reference to the class object. If an object is created with a constructor function, the constructor property holds a reference to the constructor function. Do not confuse a constructor function with a constructor method of a class. A constructor function is a Function object used to create objects, and is an alternative to using the class keyword for defining classes.

If you use the class keyword to define a class, the class's prototype object is assigned a property named constructor that holds a reference to the class object. An instance of the class inherits this property from the prototype object. For example, the following code creates a new class, A, and a class instance named myA:

  dynamic class A {}
  trace(A.prototype.constructor);      // [class A]
  trace(A.prototype.constructor == A); // true
  var myA:A = new A();
  trace(myA.constructor == A);         // true

Advanced users may choose to use the function keyword instead of the class keyword to define a Function object that can be used as a template for creating objects. Such a function is called a constructor function because you can use it in conjunction with the new operator to create objects. If you use the function keyword to create a constructor function, its prototype object is assigned a property named constructor that holds a reference to the constructor function. If you then use the constructor function to create an object, the object inherits the constructor property from the constructor function's prototype object. For example, the following code creates a new constructor function, f, and an object named myF:

  function f() {}
  trace(f.prototype.constructor);      // function Function() {}
  trace(f.prototype.constructor == f); // true
  var myF = new f();
  trace(myF.constructor == f);         // true

Note: The constructor property is writable, which means that user code can change its value with an assignment statement. Changing the value of the constructor property is not recommended, but if you write code that depends on the value of the constructor property, you should ensure that the value is not reset. The value can be changed only when the property is accessed through the prototype object (for example, className.prototype.constructor).

See also

prototypeproperty 
public static var prototype:Object

Language Version : ActionScript 3.0
Player Version : Flash Player 9

A reference to the prototype object of a class or function object. The prototype property is automatically created and attached to any class or function object that you create. This property is static in that it is specific to the class or function that you create. For example, if you create a class, the value of the prototype property is shared by all instances of the class and is accessible only as a class property. Instances of your class cannot directly access the prototype property.

A class's prototype object is a special instance of that class that provides a mechanism for sharing state across all instances of a class. At run time, when a property is not found on a class instance, the delegate, which is the class prototype object, is checked for that property. If the prototype object does not contain the property, the process continues with the prototype object's delegate checking in consecutively higher levels in the hierarchy until Flash Player finds the property.

Note: In ActionScript 3.0, prototype inheritance is not the primary mechanism for inheritance. Class inheritance, which drives the inheritance of fixed properties in class definitions, is the primary inheritance mechanism in ActionScript 3.0.

See also

Constructor Detail
Object()Constructor
public function Object()

Creates an Object object and stores a reference to the object's constructor method in the object's constructor property.

See also

Method Detail
hasOwnProperty()method
AS3 function hasOwnProperty(name:String):Boolean

Language Version : ActionScript 3.0
Player Version : Flash Player 9

Indicates whether an object has a specified property defined. This method returns true if the target object has a property that matches the string specified by the name parameter, and false otherwise. The following types of properties cause this method to return true for objects that are instances of a class (as opposed to class objects):

The following types of properties cause this method to return false for objects that are instances of a class:

ActionScript 3.0 also has class objects, which are direct representations of class definitions. When called on class objects, the hasOwnProperty() method returns true only if a property is a static property defined on that class object. For example, if you create a subclass of Array named CustomArray, and define a static property in CustomArray named foo, a call to CustomArray.hasOwnProperty("foo") returns true. For the static property DESCENDING defined in the Array class, however, a call to CustomArray.hasOwnProperty("DESCENDING") returns false.

Note: Methods of the Object class are dynamically created on Object's prototype. To redefine this method in a subclass of Object, do not use the override keyword. For example, A subclass of Object implements function hasOwnProperty():Boolean instead of using an override of the base class.

Parameters

name:String — The property of the object.

Returns
Boolean — If the target object has the property specified by the name parameter this value is true, otherwise false.
isPrototypeOf()method 
AS3 function isPrototypeOf(theClass:Object):Boolean

Language Version : ActionScript 3.0
Player Version : Flash Player 9

Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. This method returns true if the object is in the prototype chain of the object specified by the theClass parameter. The method returns false if the target object is absent from the prototype chain of the theClass object, and also if the theClass parameter is not an object.

Note: Methods of the Object class are dynamically created on Object's prototype. To redefine this method in a subclass of Object, do not use the override keyword. For example, A subclass of Object implements function isPrototypeOf():Boolean instead of using an override of the base class.

Parameters

theClass:Object — The class to which the specified object may refer.

Returns
Boolean — If the object is in the prototype chain of the object specified by the theClass parameter this value is true, otherwise false.
propertyIsEnumerable()method 
AS3 function propertyIsEnumerable(name:String):Boolean

Language Version : ActionScript 3.0
Player Version : Flash Player 9

Indicates whether the specified property exists and is enumerable. If true, then the property exists and can be enumerated in a for..in loop. The property must exist on the target object because this method does not check the target object's prototype chain.

Properties that you create are enumerable, but built-in properties are generally not enumerable.

Note: Methods of the Object class are dynamically created on Object's prototype. To redefine this method in a subclass of Object, do not use the override keyword. For example, A subclass of Object implements function propertyIsEnumerable():Boolean instead of using an override of the base class.

Parameters

name:String — The property of the object.

Returns
Boolean — If the property specified by the name parameter is enumerable this value is true, otherwise false.
setPropertyIsEnumerable()method 
public function setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void

Language Version : ActionScript 3.0
Player Version : Flash Player 9

Sets the availability of a dynamic property for loop operations. The property must exist on the target object because this method does not check the target object's prototype chain.

Parameters

name:String — The property of the object.
 
isEnum:Boolean (default = true) — If set to false, the dynamic property does not show up in for..in loops, and the method propertyIsEnumerable() returns false.

See also

toString()method 
public function toString():String

Player Version : Flash Player 9

Returns the string representation of the specified object.

Note: Methods of the Object class are dynamically created on Object's prototype. To redefine this method in a subclass of Object, do not use the override keyword. For example, A subclass of Object implements function toString():String instead of using an override of the base class.

Returns
String — A string representation of the object.
valueOf()method 
public function valueOf():Object

Player Version : Flash Player 9

Returns the primitive value of the specified object. If this object does not have a primitive value, the object itself is returned.

Note: Methods of the Object class are dynamically created on Object's prototype. To redefine this method in a subclass of Object, do not use the override keyword. For example, A subclass of Object implements function valueOf():Object instead of using an override of the base class.

Returns
Object — The primitive value of this object or the object itself.

See also

Examples How to use examples
ObjectExample.as

The following example uses the classes ObjectExample and Circle to demonstrate the dynamic nature of the Object class, and how value objects can be transformed into Shape objects and then added to the stage at the specified x/y coordinates.

The example creates the value objects firstInitObj and secondInitObj. The custom class Circle accepts the value object and loops over it while setting its matching internal properties to those defined in the value object.

package {
    import flash.display.Sprite;

    public class ObjectExample extends Sprite {
        public function ObjectExample() {
            var firstInitObj:Object = new Object();
            firstInitObj.bgColor = 0xFF0000;
            firstInitObj.radius = 25;
            firstInitObj.xCenter = 25;
            firstInitObj.yCenter = 25;
                        
            var firstCircle:Circle = new Circle(firstInitObj);
            addChild(firstCircle);
            firstCircle.x = 50;
            firstCircle.y = 50;

            var secondInitObj:Object = {bgColor:0xCCCCCC, radius:50, xCenter:50, yCenter:50};

            var secondCircle:Circle = new Circle(secondInitObj);            
            addChild(secondCircle);
            secondCircle.x = 100;
            secondCircle.y = 100;
        }
        
    }
}

import flash.display.Shape;
    
class Circle extends Shape {
    public var bgColor:Number = 0xFFFFFF;
    public var radius:Number = 0;
    public var xCenter:Number = 0;
    public var yCenter:Number = 0;
        
    public function Circle(initObj:Object) {
        for(var i:String in initObj) {
            this[i] = initObj[i];
        }
        draw();
    }
        
    public function draw():void {
        graphics.beginFill(bgColor);
        graphics.drawCircle(xCenter, yCenter, radius);
        graphics.endFill();
    }
}